display the time on the webpage, if take is the user this machine time, because the user's time is often inaccurate, therefore displays the question. And the server time generally will not be too large error, so it is best to display the server time
The following is an example of ASP+JS.
The following is an analysis of the code structure, first getting the server time:
<%
D=date ()
T=time ()
%>
var t0=new Date (). GetTime ();
var nyear=<%=year (d)%>;
var Nmonth=<%=month (d)%>;
var nday=<%=day (d)%>;
var nwday=<%=weekday (d)%>-1;
var nhrs=<%=hour (t)%>;
var nmin=<%=minute (t)%>;
var nsec=<%=second (t)%>;
//Get the difference between native time and server time
var dectime=new Date (nyear,nmonth-1,nday,nhrs,nmin,nsec). GetTime ()-t0;
Nday=-1;
// Span
document.write ("<span id=" Clock "style=" Word-break:keep-all "></span>") for displaying time;
//Time calculation function:
Function Newtick () {
var noww=new Date ();
var t1=noww.gettime ();
Noww.settime (t1+dectime);
if ( Noww.getdate ()!=nday) {
Nyear=noww.getfullyear (); Nmonth=noww.getmonth () +1;nwday=noww.getday (); nday= Noww.getdate ();
}
Nhrs=noww.gethours (); Nmin=noww.getminutes (); Nsec=noww.getseconds ();
}
//Time display function:
function Draw () {
Newtick ();///Calculate First
var s=nyear+ ' year ' +nmonth+ ' month ' +nday+ ' Day ' + ' Week ' +cweekday (nwday) + "+shapetime" (NHRS,NMIN,NSEC); The
s+= "lunar" +lmonth+ "month" +lday;//displays the lunar calendar
document.getElementById ("clock"). Innerhtml=s;
//re-obtain the native time every 500 milliseconds:
settimeout ("Draw ()", 500);
}
Start showing:
Draw ();
Other questions:
The time the server gets cannot be cached locally, so add the cache control function to the code.
Also to prevent other sites hotlinking your server time code, so to join the anti-theft chain function.
If you need to display the lunar calendar, you will also need to add a lunar operation function.