Use ajax to obtain the date value on the response header. Note the time zone. In the chrome development tool header, all values are Greenwich Mean Time, which is 8 hours less than Beijing time, the obtained time zone is related to the server settings. The following method is recommended:
// Obtain the current server time from the response header. The function getServerTime () {var xmlHttp = false; try {xmlHttp = new ActiveXObject ("Msxml2.XMLHTTP ");} catch (e) {try {xmlHttp = new ActiveXObject ("Microsoft. XMLHTTP ") ;}catch (e2) {xmlHttp = false ;}} if (! XmlHttp & typeof XMLHttpRequest! = 'Undefined') {xmlHttp = new XMLHttpRequest ();} xmlHttp. open ("GET", window. location. href. toString (), false); xmlHttp. setRequestHeader ("Range", "bytes =-1"); xmlHttp. send (null); var severtime = new Date (xmlHttp. getResponseHeader ("Date"); return severtime}
In addition, there is a problem that the cache does not update the time through the ajax method of jquery.
Htmlobj = $. ajax ({url: "a.txt", async: false });
$ ("# MyDiv" ).html (htmlobj. responseText );
ResponseText: returned content
Async: false indicates that the Code after the return value is executed (synchronous thread)
Htmlobj. getResponseHeader ("Date ")
Obtain the time in the response header (Greenwich Mean Time, 8 hours slower than Beijing Time ),
When cache exists, the value in IE is null, and chrome time is not updated.
Firefox has frequent requests and there is a delay in time. The time will not be updated in a certain period of time (about one minute from the previous refresh ).