console.log(new Date());//Tue Jan 17 2017 14:00:28 GMT+0800 當前時間
console.log(new Date(2017,1,17,13,12,11));//Fri Feb 17 2017 13:12:11 GMT+0800 直接初始化一個日期,第二個參數(shù)1代表二月
console.log(Date.now());//1484633049959 毫秒數(shù)蛋辈,IE9+
console.log(+new Date());//1484633049959 毫秒數(shù) IE8可以這么實現(xiàn)
a=new Date();
i=0;
console.log(a);//當前時間
console.log(a.getTime());//1484636462599 當前時間毫秒數(shù),和 +a一個效果
console.log(a.setTime(1484633049959));//1484633049959 設(shè)置一個日期
console.log(a.getFullYear());//2017 a的年
console.log(a.setUTCFullYear("2026"));//1768629849959 年替換成2016年
console.log("============================================");
a=new Date();
console.log(a.getMonth());//0 當前時間的月份 ,0作為第一個月的開始
console.log(a.getUTCMonth());//0 返回的是UTC的月份
console.log(a.getDate());// 返回日
console.log(a.getUTCDate());//返回UTC日
console.log(a.setDate(54));//設(shè)置日期策彤,如果查過當前月的最大天數(shù)须床,則月加一
console.log(a.setUTCDate(54));//同上
console.log("============================================");
a=new Date();
console.log(a.getHours());//獲得小時 0~23
//還有一些其他的時分秒方法庭砍,基本都是get,set,getUTC,setUTCDate
console.log(a.getMinutes());//分
console.log(a.getSeconds());//秒
console.log(a.getMilliseconds());//毫秒
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者