. Net dynamically displays the current time (client javascript)

Source: Internet
Author: User

I personally think Ajax is not good for Ajax! Isn't JavaScript ideal for processing on the client? Copy codeThe Code is as follows: function Timer (span)
{
Var tmp = new Date ();
Var milsecs = Date. parse (tmp. getMonth () + "-" + tmp. getDay () + "-" + tmp. getFullYear () + "" + document. getElementById ('lbl _ Hour '). innerText + ":" + document. getElementById ('lbl _ Minute '). innerText + ":" + document. getElementById ('lbl _ second '). innerText );
Var timer = new Date (milsecs + span );
Var seconds, minutes, hours, date;
If (timer. getSeconds () <10)
Seconds = "0" + timer. getSeconds ();
Else
Seconds = timer. getSeconds ();
If (timer. getMinutes () <10)
Minutes = "0" + timer. getMinutes ();
Else
Minutes = timer. getMinutes ();
If (timer. getHours () <10)
Hours = "0" + timer. getHours ();
Else
Hours = timer. getHours ();
Date = timer. getDate ();
Document. getElementById ('lbl _ second'). innerText = seconds;
Document. getElementById ('lbl _ Minute '). innerText = minutes;
Document. getElementById ('lbl _ Hour '). innerText = hours;
}
// Obtain the server time check every updatespan minute, and update the local clock every second.
Function GetServerTime (updatespan)
{
Var clientspan = 1*1000;
// Update the local clock
SetInterval ("Timer (" + clientspan + ")", clientspan );
// Synchronize the server clock
SetInterval ("window. location. href = 'current url'", updatespan );
}

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.