<span id= "Curtime" ></span> <script type= "Text/javascript" ><!--setinterval ("curtime.innerhtml =new date (). toLocaleString () + ' Week ' + ' Day 123456 '. CharAt (New Date (). Getday ()); ", 1000); --></script>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]
I am in the OA of an attendance program, to dynamically display the time of the server, so that employees know whether the current can work, and the client for various reasons time and server is inconsistent, so can not use the above code, improved a bit:
<span id= "Curtime" ></span> <script type= "Text/javascript" ><!--//page to start timing date (typically the server date), Like 2007-01-12 11:34:55. var beginadd = new Date (2007,0,12,11,34,55); var begindate = new Date (); function ShowTime () {var now = new Date (); var diff = (now-begindate); Beginadd.setmilliseconds (Beginadd.getmilliseconds () + diff); Begindate = Now; document.getElementById ("Curtime"). InnerHTML = beginadd.tolocalestring () + ' Week ' + ' Day 123456 '. CharAt (Beginadd.getday () ); } setinterval ("ShowTime ();", 1000); --></script>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]
Finally, add a meizz Format function (slightly modified), the final version is as follows:
<span id= "Curtime" ></span> <script type= "Text/javascript" ><!--//page to start timing date (typically the server date), Like 2007-01-12 11:34:55. var beginadd = new Date (2007,0,12,11,34,55); var begindate = new Date (); Function abc () {var now = new Date (); var diff = (now-begindate); Beginadd.setmilliseconds (Beginadd.getmilliseconds () + diff); Begindate = Now; document.getElementById ("Curtime"). InnerHTML = Beginadd.format ("YYYY year mm month DD Day HH:MM:SS week W"); } setinterval ("ABC ();", 1000); Date.prototype.format = function (format) {var obj = {"m+": This.getmonth () + 1,//returns the actual month "d+": t His.getdate (),//Returns the day of the Month "h+": this.gethours (),//Return Hour "m+": this.getminutes (),//Return minute "s+": this.getsec Onds (),//return second "q+": Math.floor (This.getmonth () + 3)/3),//Back to Quarter "S": This.getmilliseconds (),//back to milliseconds "W": This.getday (),//Return of the week, 0 for Sunday "W": "Day 123456". CharAt (This.getday ())//Return of the days of the week in Chinese Representation}//yearSeparate processing if (/(y+)/.test (format)) format = Format.replace (regexp.$1, this.getfullyear () + ""). substr (4-regexp. $1.length)); Other format processing for (var k in obj) {if (New RegExp ("+ K +")). Test (format) format = Format.replace (RegEx p.$1, regexp.$1.length = 1? Obj[k]: ("+ obj[k]"). substr (("" "+ obj[k]). length); } return format; }//--></script>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]