Javascript 世界时区时间显示代码
Javascript 世界時間時間顯示
//https://gist.github.com/1326893https://gist.github.com/1326893
//20120511 Geovin Du 塗聚文
function calcTime(city, offset) {
var d = new Date();
utc = d.getTime() + (d.getTimezoneOffset() * 60000);
var nd = new Date(utc + (3600000 * offset));
var gmtTime = new Date(utc)
var day = nd.getDate();
var month = nd.getMonth();
var year = nd.getYear();
var hr = nd.getHours(); //+ offset
var min = nd.getMinutes();
var sec = nd.getSeconds();
if(year = 24){
hr = hr-24
day -= -1
}
if (hr monthDays[month]){
day = 1
if(month == 11){
month = 0
year -= -1
}
else{
month -= -1
}
}
return city+":The local time is"+monthArray[month] + " " + day + ", " + year + "
" + hr + ":" + min + ":" + sec
//return "The local time in " + city + " is " + nd.toLocaleString()+;
}
function worldClockZone(){
document.getElementById('local').innerHTML = "The local time is " + (new Date()).toLocaleString();
document.getElementById('localutc').innerHTML = "The local time is " + (new Date()).toLocaleString();
document.getElementById('bombay').innerHTML = calcTime('bombay', '+5.5');
document.getElementById('singapore').innerHTML = calcTime('singapore', '+8');
document.getElementById('tokyo').innerHTML = calcTime('tokyo', '+9');
document.getElementById('london').innerHTML =calcTime('london', '+1');
setTimeout("worldClockZone()", 1000)
}
window.onload=worldClockZone;
Last modified: Mon Oct 31 02:04:17 BRST 2011
[Ctrl+A 全选 注:如需引入外部Js需刷新才能执行]