The current B/S project has a requirement: display the server time clock in the browser. It would be easy to display the client clock, but the server segment clock would be displayed ....... The page cannot be refreshed every second. The first idea is to get the time difference between the client and the server, and then display it in the client using the JS script. This is naturally because the current time of the client is added with the time difference.
Previously, I used Javascript. It seems that there is no easy way to simply implement tasks such as "computing time difference" and "plus a time interval. Fortunately, JS does not, but vbs does. datadiff and dateadd functions can easily complete the preceding tasks. The following is the htmlCode.
<! Doctype HTML public "-// W3C // dtd html 4.01 transitional // en" >
< Html >
< Head >
< Title > Server time </ Title >
< Meta HTTP-equiv = "Content-language" Content = "ZH-CN" >
< Meta HTTP-equiv = "Content-Type" Content = "Text/html; charset = gb2312" >
< Script Language = "VBScript" >
Dim Seconddiff
Sub Updatetime ()
Clienttime. innertext = Now ()
Servertime. innertext = Dateadd ( " S " , Seconddiff, Now ())
End sub
Sub Settime (serverdatetime)
' Client time
Clientdatetime = Now ()
' Second difference
Seconddiff = Datediff ( " S " , Clientdatetime, serverdatetime)
' Update per second
Ointerval = Setinterval ( " Updatetime () " , 1000 )
End sub
</ Script >
</ Head >
< Body >
< Script > Settime ("2007-10-20 12:30:33") </ Script >
Client time: < Label ID = "Clienttime" > </ Label > < BR >
Server time: < Label ID = "Servertime" > </ Label >
</ Body >
</ Html >