創(chuàng)建
# now()方法返回自1970年1月1日 00:00:00 UTC到當(dāng)前時(shí)間的毫秒數(shù),類型為Number。
> Date.now();
< 1522828625620
# new Date();
# new Date(value);
# new Date(dateString);
# new Date(year, month[, day[, hour[, minutes[, seconds[, milliseconds]]]]]);
> var date=new Date();
> date;
< Wed Apr 04 2018 15:50:05 GMT+0800 (CST);
> var d1 = new Date(1522830797376);
> d1
< Wed Apr 04 2018 16:33:17 GMT+0800 (CST)
# 年份為必填
> var d2 = new Date("2018-4-4");
> d2
< Wed Apr 04 2018 15:30:21 GMT+0800 (CST)
# 年份和月份為必填
> var d3 = new Date(2018,3,4,15,30,21);
> d3
< Wed Apr 04 2018 15:30:21 GMT+0800 (CST)
> typeof(date);
< "object"
獲取
# 年份
> date.getFullYear();
< 2018
# 月份,為基于0的值(0表示一年中的第一月)。
> date.getMonth();
< 3
# 幾號(hào)
> date.getDate();
< 4
# 周幾,0表示星期天。
> date.getDay();
< 3
# 小時(shí)
> date.getHours();
< 15
# 分鐘
> date.getMinutes();
< 50
# 秒
> date. getSeconds();
< 05
# 從1970年1月1日 0:0:0(UTC,即協(xié)調(diào)世界時(shí))距離該日期對(duì)象所代表時(shí)間的毫秒數(shù)。
> date.getTime();
< 1522828205871
轉(zhuǎn)換
> date.toDateString();
< "Wed Apr 04 2018"
# 顯示當(dāng)前地區(qū)的時(shí)間日期格式,不用于計(jì)算。
> date.toLocaleDateString();
< "2018/4/4"
> date.toString();
< "Wed Apr 04 2018 15:50:05 GMT+0800 (CST)"
> date.toLocaleString();
< "2018/4/4 下午3:50:05"
# 以人類易讀形式返回一個(gè)日期對(duì)象時(shí)間部分的字符串,該字符串以美式英語(yǔ)格式化。
> date.toTimeString()
< "15:50:05 GMT+0800 (CST)"
最后編輯于 :
?著作權(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)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。