console.log(new Date());//Tue Jan 17 2017 14:00:28 GMT+0800 當(dāng)前時(shí)間
console.log(new Date(2017,1,17,13,12,11));//Fri Feb 17 2017 13:12:11 GMT+0800 直接初始化一個(gè)日期,第二個(gè)參數(shù)1代表二月
console.log(Date.now());//1484633049959 毫秒數(shù),IE9+
console.log(+new Date());//1484633049959 毫秒數(shù) IE8可以這么實(shí)現(xiàn)
a=new Date();
i=0;
console.log(a);//當(dāng)前時(shí)間
console.log(a.getTime());//1484636462599 當(dāng)前時(shí)間毫秒數(shù),和 +a一個(gè)效果
console.log(a.setTime(1484633049959));//1484633049959 設(shè)置一個(gè)日期
console.log(a.getFullYear());//2017 a的年
console.log(a.setUTCFullYear("2026"));//1768629849959 年替換成2016年
console.log("============================================");
a=new Date();
console.log(a.getMonth());//0 當(dāng)前時(shí)間的月份 ,0作為第一個(gè)月的開(kāi)始
console.log(a.getUTCMonth());//0 返回的是UTC的月份
console.log(a.getDate());// 返回日
console.log(a.getUTCDate());//返回UTC日
console.log(a.setDate(54));//設(shè)置日期,如果查過(guò)當(dāng)前月的最大天數(shù),則月加一
console.log(a.setUTCDate(54));//同上
console.log("============================================");
a=new Date();
console.log(a.getHours());//獲得小時(shí) 0~23
//還有一些其他的時(shí)分秒方法,基本都是get,set,getUTC,setUTCDate
console.log(a.getMinutes());//分
console.log(a.getSeconds());//秒
console.log(a.getMilliseconds());//毫秒
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。