The following is an example of ASP+JS. Specific code can be downloaded to the website time Code of this website.
The following is an analysis of the code structure, first getting the server time:
Copy Code code as follows:
<%
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 for displaying time
document.write ("<span id=\" clock\ "style=\" word-break:keep-all\ "></span>");
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);
s+= "lunar" +lmonth+ "month" +lday;//display 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.
Please download the code to see for yourself.