$(document).ready(function() { var d = new Date(); var timezone=document.getElementById('countrytime').innerHTML; time = d.getTime() + (d.getTimezoneOffset() * 60000); var time = 1634534613000+2000; var bjtime = time; var gmttime = time-8*3600000; var localtime =gmttime+timezone*3600000; var week = [ '星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六', ]; setInterval(function(){ var bjTime = new Date(bjtime); var gmTime = new Date(gmttime); var lTime = new Date(localtime); $('#gmttime').text('当前世界时间(GMT):'+gmTime.getFullYear()+'-'+(gmTime.getMonth()+1)+'-'+gmTime.getDate()+' '+IfZero(gmTime.getHours())+':'+IfZero(gmTime.getMinutes())+':'+IfZero(gmTime.getSeconds())); $('#bjtime').text('当前北京时间:'+bjTime.getFullYear()+'-'+(bjTime.getMonth()+1)+'-'+bjTime.getDate()+' '+IfZero(check24(bjTime.getHours()))+':'+IfZero(bjTime.getMinutes())+':'+IfZero(bjTime.getSeconds())); $('#localtime').text(IfZero(check24(lTime.getHours()))+':'+IfZero(lTime.getMinutes())+':'+IfZero(lTime.getSeconds())); $('#localdate').text(IfZero(lTime.getFullYear())+'年'+IfZero(lTime.getMonth()+1)+'月'+IfZero(lTime.getDate())+'日 '+week[lTime.getDay()]); gmttime= parseInt(gmttime) + 1000; bjtime= parseInt(bjtime) + 1000; localtime = parseInt(localtime)+1000; },1000); function IfZero(num) { return ((num <= 9) ? ("0" + num) : num); } function check24(hour) { return (hour >= 24) ? hour - 24 : hour; } });