JavaScript Print current time implementation ideas and code _javascript tips

Source: Internet
Author: User
Tags getdate local time
Copy Code code as follows:

<title></title>

<script>

/*

Declaration time
var date = new Date ();
alert (date);/Current Time
Alert (date.tolocalestring ());//Convert to local time
Alert (Date.getfullyear ());//Show Year
Alert (Date.getmonth () + 1);//Display month 0-11, you need to add 1
Alert (Date.getdate ());//display date in January
Alert (Date.getday ());//show the date of the week, Day of the week
Alert (date.gethours ());//Get hour time
Alert (Date.getminutes ());//Get current minute
Alert (Date.getseconds ());//get current number of seconds
Alert (Date.getmilliseconds ());//Get the current number of milliseconds
Alert (Date.gettime ())//Gets the millisecond value from 0 o'clock midnight, January 1, 1970, to the current time
*/
Get year, month, day, hour, minute, 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 ();

Month is displayed as two digits as in September
if (Month < 10) {
month = "0" + month;
}
if (Date < 10) {
Date = "0" + date;
}

Time Stitching
var dateTime = year + "years" + month + "Month" + Date + "Day" + Hours + "time" + minutes + "min" + seconds + "seconds";

document.write (dateTime);//Print Current time



</script>


<body>
<!--event response-->
<input type = "button" value= "click" onclick= "Show ()"/>
</body>

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.