JS Date function

Source: Internet
Author: User

The date function of JS has the following several:

getFullYear (); Get when the year before

GetMonth (); Get current month, need to add 1, and only one digit, if less than 10 need to precede plus 0

GetDate (); Gets the current day, only one digit, if less than 10 requires a front plus 0

GetTime ();//Returns the number of milliseconds since January 1, 1970.

toUTCString ();//Converts the date of the day (in UTC) to a string.

GetDay ();//Returns the number of weeks

GetHours ();//Return hour

Getminutes ();//Return minutes

Getseconds ();//return seconds

Timer Example:

1 setinterval (2         function () {3         var x = document.getElementById ("demo"); 4         X.innerhtml=date (). Split ("") [4]; 5                   },6         );

or the direct acquisition of seconds and minutes:

1 functionstartTime ()2 {3 vartoday=NewDate ();4 varH=today.gethours ();5 varm=today.getminutes ();6 vars=today.getseconds ();7 //add a zero in front of numbers<108m=Checktime (m);9s=Checktime (s);Tendocument.getElementById (' txt '). innerhtml=h+ ":" +m+ ":" +s; OneT=settimeout (function() {startTime ()},500); A } -  - functionchecktime (i) the { - if(i<10) -   { -I= "0" +i; +   } - returni; +}

JS Date function

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.