Print the current time implementation ideas and code in JavaScript

Source: Internet
Author: User
Tags current time datetime local time min

  Printing The current time there are many ways, in this article for you to describe the use of JavaScript is how to do, specifically implemented as follows, interested friends can refer to the following

Copy code code as follows: <html>  <head>  <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);//Show month 0-11, you need to add 1  alert ( Date.getdate ())//display January date   alert (Date.getday ());//Display the date of the week, Week   alert (date.gethours ());/Get hour time   Alert (Date.getminutes ());//Get the current minute   alert (date.getseconds ());//Get the current number of seconds   alert (date.getmilliseconds ());// Gets the current number of milliseconds   alert (date.gettime ());//Gets the millisecond value   */ /////////////////////////////////////////min = new Date ();  var year = mydate.getfullyear ();  var month = Mydate.getmonth () + 1;  var Date = mydate.getd Ate ();  var hours = mydate.gethours ();  var minutes = mydate.getminutes ();  var seconds = mydate.getseconds ();   //month display as two digits as September   if (month <) {  month ="0" + month; }  if (date <) {  date = "0" + date; }   //Time stitching   var dateTime = ye AR + "Year" + Month + "Month" + Date + "Day" + Hours + "time" + minutes + "min" + seconds + "SEC";    document.write (dateTime); /print 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.