JS Gets the current date time

Source: Internet
Author: User

<script>var mydate = new Date ();       Mydate.getyear ();   Gets the current year (2-bit)//alert (Mydate.getyear ())//2009 mydate.getfullyear (); Get the full year (4-bit, 1970-????) Alert (Mydate.getfullyear ());      Mydate.getmonth (); Get the current month (0-11, 0 for January)//alert (Mydate.getmonth ());       7 (actually August) mydate.getdate (); Get current day (1-31)//alert (Mydate.getdate ());        Mydate.getday (); Get Current week x (0-6, 0 for Sunday)//alert (Mydate.getday ());       4 represents Thursday mydate.gettime ();      Gets the current time (the number of milliseconds starting in 1970.1.1) mydate.gethours (); Gets the current number of hours (0-23)//alert (Mydate.gethours ());    9 stands for 9 points mydate.getminutes (); Gets the current number of minutes (0-59)//alert (Mydate.getminutes ());    45 min mydate.getseconds (); Gets the current number of seconds (0-59)//alert (Mydate.getseconds ());   40 seconds number mydate.getmilliseconds ();    Gets the current number of milliseconds (0-999) mydate.tolocaledatestring ();    Gets the current date var mytime=mydate.tolocaletimestring ();       Get current time//alert (mytime);//9:40:18 mydate.tolocalestring (); Get date and Time//alert (Mydate.tolocalestring ()); August 13, 2009 9:40:58&LT;/script> 

<script>function Curdatetime () {   var d = new Date ();   var year = D.getyear ();   var month = D.getmonth () + 1;   var date = D.getdate ();   var day = D.getday ();   var curdatetime = year;   if (Month > 9)    curdatetime = curdatetime + month;   else    curdatetime = curdatetime + "0" + month;   if (Date > 9)    curdatetime = curdatetime + date;   else    curdatetime = curdatetime + "0" + date;   Myform.kprq.value = Curdatetime;   Alert ("Current date" +curdatetime);   Document.getelementbyidx_x ("date"). Value=curdatetime; </script>

function Curdatetime () {       var d = new Date ();       var year = D.getfullyear ();       var month = D.getmonth () + 1;       var date = D.getdate ();       var day = D.getday ();       var curdatetime = year;       if (Month > 9)          curdatetime = Curdatetime + "-" + month;       else          curdatetime = curdatetime + "-0" + month;       if (Date > 9)          curdatetime = Curdatetime + "-"  + date;       else          curdatetime = curdatetime + "-0" + date;       return curdatetime; }

JS Gets the current date time

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.