How to print the current time implementation and code in javascript
There are many ways to print the current time. This article describes in detail how to use javascript. The specific implementation is as follows. If you are interested, refer
Copy the Code as follows:
<Html>
<Head>
<Title> </title>
<Script>
/*
// Declare the time
Var date = new Date ();
Alert (date); // current time
Alert (date. toLocaleString (); // convert to local time
Alert (date. getFullYear (); // displays the year.
Alert (date. getMonth () + 1); // displays the month 0-11, which requires 1
Alert (date. getDate (); // display the date from January 1, January
Alert (date. getDay (); // display the date of the week, the day of the week
Alert (date. getHours (); // obtain the hour time
Alert (date. getMinutes (); // get the current minute
Alert (date. getSeconds (); // gets the current number of seconds
Alert (date. getMilliseconds (); // gets the current number of milliseconds
Alert (date. getTime (); // gets the millisecond value from midnight, January 1, January 1, 1970, to the current time.
*/
// Obtain the year, month, day, hour, minute, and second respectively.
Var myDate = new Date ();
Var year = myDate. getFullYear ();
Var month = myDate. getMonth () + 1;
Var date = myDate. getDate ();
Var hours = myDate. getHours ();
Var minutes = myDate. getMinutes ();
Var seconds = myDate. getSeconds ();
// The month is displayed as two digits, for example, January 1, September.
If (month <10 ){
Month = "0" + month;
}
If (date <10 ){
Date = "0" + date;
}
// Time Merging
Var dateTime = year + "year" + month + "month" + date + "day" + hours + "Hour" + minutes + "Minute" + seconds + "second ";
Document. write (dateTime); // print the current time
</Script>
</Head>
<Body>
<! -- Event Response -->
<Input type = "button" value = "click" onclick = "show ()"/>
</Body>
</Html>