中国及德国时间JS代码
作者:shao65308 日期:2013-04-23
程序代码
var timerRunning = false;
function checkDateTime() {
if (timerRunning) {
clearTimeout(updatetime);
timerRunning = false;
}
for (var i = 1; i <= 2; i++) {
var today = new Date();
var month = today.getMonth() + 1;
var date = today.getDate();
if (i == 2){ //德国时间
if( (month>3 || month==3 && date>24) && (month<10 || month==10 && date<24) ) //夏时制 -6小时
today = today.dateAdd("h", -6);
else
today = today.dateAdd("h", -7);
}
var year = today.getYear() + 00;
month = today.getMonth() + 1;
date = today.getDate();
var day = today.getDay();
var hour = today.getHours();
var minute = today.getMinutes();
var second = today.getSeconds();
var dateTime = addZero(hour) + ":" + addZero(minute) + ":" + addZero(second) + "," + addZero(month) + "/" + addZero(date);
if (i == 1) //北京时间
$("#bj_time").text(dateTime);
else//德国时间
$("#dg_time").text(dateTime);
}
updatetime = setTimeout("checkDateTime()", 1000);
timerRunning = true;
}
function addZero(num, end) {
return num < 10 ? "0" + num : num;
}
$(document).ready(function () {
checkDateTime();
});
/* 得到日期年月日等加数字后的日期 */
Date.prototype.dateAdd = function (interval, number) {
var d = this;
var k = { 'y': 'FullYear', 'q': 'Month', 'm': 'Month', 'w': 'Date', 'd': 'Date', 'h': 'Hours', 'n': 'Minutes', 's': 'Seconds', 'ms': 'MilliSeconds' };
var n = { 'q': 3, 'w': 7 };
eval('d.set' + k[interval] + '(d.get' + k[interval] + '()+' + ((n[interval] || 1) * number) + ')');
return d;
}
评论: 0 | 引用: 0 | 查看次数: 3235
发表评论
你没有权限发表评论!