//獲取當前時間
var date = new Date();
var year = date.getFullYear();
var month = date.getMonth() + 1;
var day = date.getDate();
if (month < 10) {
month = "0" + month;
}
if (day < 10) {
day = "0" + day;
}
var nowDate = year + "-" + month + "-" + day;
這樣控制台輸出一下,就是當前時間的年月日格式了,以今天為例,控制台console.log(nowDate),你會看到結果為: 2017-07-13
