function getDate(){ var myDate = new Date(); //獲取當前年 var year = myDate.getFullYear(); //獲取當前月 var month = myDate.getMonth() + 1; //獲取當前日 var date = my ...
function getDate(){
var myDate = new Date();
//獲取當前年
var year = myDate.getFullYear();
//獲取當前月
var month = myDate.getMonth() + 1;
//獲取當前日
var date = myDate.getDate();
var h = myDate.getHours(); //獲取當前小時數(0-23)
var m = myDate.getMinutes(); //獲取當前分鐘數(0-59)
var s = myDate.getSeconds();
//獲取當前時間
var now = year + '-' + conver(month) + "-" + conver(date) + " " + conver(h) + ':' + conver(m) + ":" + conver(s);
}
//日期時間處理
function conver(s) {
return s < 10 ? '0' + s : s;
}
//列印輸出
console.log(getDate());
Live and learn!