We often use the date, the following is the method of JS get date, there are other methods will be updated occasionally.
1 //Get current date time2 functionGetCurrentDateTime () {3 varDate=NewDate ();4 varYear=date.getfullyear ();5 varMonth=date.getmonth (+1);6 varday=date.getdate ();7 varhours=date.gethours ();8 varminutes=date.getminutes ();9 varseconds=date.getseconds ();Ten returnyear+ "-" +formatzero (month) + "-" +formatzero (Day) + "" +formatzero (Hours) + ":" +formatzero (minutes) + ":" +Formatzero (seconds); One } A - //Get Current date - functiongetcurrentdate () { the varDate=NewDate (); - varYear=date.getfullyear (); - varMonth=date.getmonth (+1); - varday=date.getdate (); + returnyear+ "-" +formatzero (month) + "-" +Formatzero (day); - } + A //Format Date Time at functionFormatzero (n) { - if(n>=0&&n<=9){ - return"0" +N; -}Else{ - returnN; - } in}
View Code
JS Get Current Date method