Javascript real-time display of Beijing time, javascript Beijing Time
This article describes how to display the Beijing time in javascript in real time. Share it with you for your reference. The details are as follows:
This page displays the Beijing time in real time. You can change the time zone to display the world time. The Code is as follows:
Copy codeThe Code is as follows: <script type = "text/javascript">
Date. prototype. strftime = function (format ){
Var o = {
"M +": this. getMonth () + 1, // month
"D +": this. getDate (), // day
"H +": this. getHours (), // hour
"M +": this. getMinutes (), // minute
"S +": this. getSeconds (), // second
"Q +": Math. floor (this. getMonth () + 3)/3), // quarter
"S": this. getMilliseconds () // millisecond
}
If (/(y +)/. test (format )){
Format = format. replace (RegExp. $1, (this. getFullYear () + ""). substr (4-RegExp. $1. length ));
}
For (var k in o ){
If (new RegExp ("(" + k + ")"). test (format )){
Format = format. replace (RegExp. $1, RegExp. $1. length = 1? O [k]: ("00" + o [k]). substr ("" + o [k]). length ));
}
}
Return format;
}
Function UTCToLocalTimeString (d, format ){
Var timeOffsetInHours = (new Date (). getTimezoneOffset ()/60) +-10;
D. setHours (d. getHours () + timeOffsetInHours );
Return d. strftime (format );
}
</Script>
<Script>
SetInterval (function () {var time = UTCToLocalTimeString (new Date (), 'yyyy/MM/dd hh: mm: ss'); document. getElementById ("bjTime "). innerHTML = time;}, 1000 );
</Script>
<Span id = "bjTime"> </span>
I hope this article will help you design javascript programs.