getMilliseconds();//獲取毫秒值
getSeconds();//獲取秒
getMinutes();//獲取分鐘
getHours();//獲取小時
getDay();//獲取星期,0-6 0:星期天
getDate();//獲取日,即當月的第幾天
getMonth();//返回月份,注意從0開始計算,這個地方坑爹,0-11
getFullYear();//返回4位的年份 如 2016
//思考:
//封裝一個函數,返回當前的時間,格式是:yyyy-MM-dd HH:mm:ss (2018-01-01 01:20:12)
function getD() {
var date = new Date();
var year = date.getFullYear();
var month = date.getMonth() + 1;
var day = date.getDate();
var h = date.getHours();
var m = date.getMinutes();
var s = date.getSeconds();
function addZero(num) {
return num < 10 ? '0'+num : num;
}
return year+ '-'+ addZero(month) +'-'+ addZero(day) +' '+ addZero(h) +':' + addZero(m) + ':' + addZero(s);
}