Dynamically display the server time clock

Source: Internet
Author: User

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 >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.