JavaScript Time Operations Summary

Source: Internet
Author: User

Source: http://www.ido321.com/847.html

In the project you need a timer, the effect is as follows:

JS Code

   1:/* Get current time * /
   2:function getcurrentdate ()
   3: {
   4:   ";
   5:   new Date ();
   6:   var curmonth = Curdate.getmonth () +1;  //Get the current month (0-11, 0 for January) 
   7:   var curday = Curdate.getdate ();       //Get current day (1-31) 
   8:   var curweekday = Curdate.getday ();    //Get Current week x (0-6, 0 for Sunday) 
   9:   var curhour = curdate.gethours ();      //Get current hours (0-23) 
  £ º   var curminute = Curdate.getminutes ();   //Gets the current number of minutes (0-59) 
  One:   var cursec =curdate.getseconds ();      //Gets the current number of seconds (0-59) 
  :   timestr = curmonth+' month ' +curday+' Day week ';  
  :   switch (curweekday)
  :   {
  :     ' Day ';  break; 
  :     ' one ';  break; 
  :     ' two ';  break; 
  :     ' three ';  break; 
  :     ' four ';  break; 
  :     ' five ';  break; 
  :     ' VI ';  break; 
  :   }
  Max:   if (Curhour < ten)
  :   {
  :     if (Curminute < ten)
  :     {
  :       if (Cursec < ten)
  :       {
  :         ' 0 ' +curhour+': 0 ' +curminute+': 0 ' +cursec;  
  :       }
  To:       Else
  :       {
  :         ' 0 ' +curhour+': 0 ' +curminute+': ' +cursec;  
  :       }
  :     }
  $:     Else
  PNS:     {
  Max:       if (Cursec < ten)
  The following:       {
  Max:         ' 0 ' +curhour+': ' +curminute+': 0 ' +cursec;  
  In:       }
  :       Else
  :       {
  : '         0 ' +curhour+': ' +curminute+': ' +cursec;  
  :       }
  :     }
  :   }
  To:   Else
  $:   {
  :     if (Curminute < ten)
  Wuyi:     {
  :       if (Cursec < ten)
  :       {
  Si:         ' +curhour+': 0 ' +curminute+': 0 ' +cursec;  
  :       }
  $:       Else
  :       {
  : '         +curhour+': 0 ' +curminute+ ':' +cursec;  
  :       }
  :     }
  I:     Else
  +:     {
  :       if (Cursec < ten)
  :       {
  : '         +curhour+': ' +curminute+': 0 ' +cursec;  
  :       }
  :       Else
  :       {
  "         +curhour+': ' +curminute+ ': '+cursec;  
  :       }
  :     }
  :   }
  :   $ ("#time"). Text (timestr); 
  A: }

Then the bar uses this function to line up.

Finally, a summary of some of the functions of the JavaScript date:

var mydate = new Date ();

Mydate.getyear (); Get Current year (2-bit)

Mydate.getfullyear (); Get the full year (4-bit, 1970-????)

Mydate.getmonth (); Get the current month (0-11, 0 for January)

Mydate.getdate (); Get current day (1-31)

Mydate.getday (); Get Current week x (0-6, 0 for Sunday)

Mydate.gettime (); Gets the current time (the number of milliseconds since 1970.1.1)

Mydate.gethours (); Get current number of hours (0-23)

Mydate.getminutes (); Gets the current number of minutes (0-59)

Mydate.getseconds (); Gets the current number of seconds (0-59)

Mydate.getmilliseconds (); Gets the current number of milliseconds (0-999)

Mydate.tolocaledatestring (); Get Current date

var mytime=mydate.tolocaletimestring (); Get current time

Mydate.tolocalestring (); Get Date and time

JavaScript Time Operations Summary

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.