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