Page real-time update time of JS instance code _javascript skills

Source: Internet
Author: User
Tags getdate

Copy Code code as follows:

function StartTime () {
var today = new Date (); Defining Date Objects
var yyyy = Today.getfullyear (); Returns the year by the getFullYear () method of the Date object
var MM = today.getmonth () + 1; Returns the year by the GetMonth () method of the Date object
var dd = today.getdate (); Returns the year by the GETDATE () method of the Date object
var hh = today.gethours (); Returns an hour by the gethours method of a Date object
var mm = Today.getminutes (); Returns a minute by the Getminutes method of a Date object
var ss = Today.getseconds (); Returns a second by the Getseconds method of a Date object
If the value of minutes or hours is less than 10, add 0 before its value, for example, if the time is 3:20 P.M. 9 seconds, show 15:20:09
MM = Checktime (mm);
DD = Checktime (DD);
MM = Checktime (mm);
SS = Checktime (ss);
Var day; Used to Save Week (Getday () method gets the week number)
if (today.getday () = = 0) Day = "Sunday"
if (today.getday () = = 1) Day = "Monday"
if (today.getday () = = 2) Day = "Tuesday"
if (today.getday () = = 3) Day = "Wednesday"
if (today.getday () = = 4) Day = "Thursday"
if (today.getday () = = 5) Day = "Friday"
if (today.getday () = = 6) Day = "Saturday"
document.getElementById (' Nowdatetimespan '). InnerHTML = yyyy + "-" + mm + "-" + dd + "" + hh + ":" + MM + ":" + SS + "" " + Day;
SetTimeout (' StartTime () ', 1000); Reload the StartTime () method per second
}

function Checktime (i) {
if (I < 10) {
i = "0" + i;
}
return i;
}

Call: <strong> current time: </strong>
<font color= "white" ><span id= "Nowdatetimespan" ></span ></font>      

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.