. NET Dynamic Display current time (client JavaScript) _ Practical Tips

Source: Internet
Author: User
Tags setinterval
Personal feeling is completely Ajax and Ajax is not good! Isn't JavaScript more ideal for client processing?
Copy Code code 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;
}
Get server time to check every updatespan minutes, update local clock every second
function GetServerTime (Updatespan)
{
var clientspan = 1*1000;
Update Local Clock
SetInterval ("Timer (" +clientspan+ ")", Clientspan);
Synchronizing server Clocks
SetInterval ("window.location.href= ' current URL '", Updatespan);
}
Related Article

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.