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 設置一個日期
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ù),則月加一
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)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。