<!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <title>获取当前时间</title> </head> <body> <script type="text/javascript"> a Date (); new new=nowvargetCurrentDate (the format) { function* / * format = 2 to the minutes * format = 1 nearest day * Get the current time*/ * var year = now.getFullYear (); // get Year var month The = now.getMonth (); // get the month var DATE = now.getDate (); // get the date var Day = now.getDay (); // to give the week var hour = now.getHours (); // get h var Minu = now.getMinutes (); // get minutes var sec = now.getSeconds (); // get second month The = month The + . 1; if (month < 10) month = "0" + month; if (date < 10) date = "0" + date; if (hour < 10) hour = "0" + hour; if (minu < 10) minu = "0" + minu; if (sec < 10) sec = "0 " + sec; var Time = " " ; // nearest days IF (the format == . 1 ) { Time = year + " - " + month The + " - " + DATE; } // to the minutes the else IF (the format == 2 ) { Time = year + " - " + month The + " - " + date+ " " + hour + ":" + minu + ":" + sec; } return time; } alert(getCurrentDate(2)); </script> </body> </html>
From the micro-channel public number: Programming Society
Advanced programmers daily book, please pay attention!