How to print the current time implementation and code in javascript

Source: Internet
Author: User

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>

 

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.