date&time

var time = new Date(2019, 7, 23) // 創(chuàng)建一個(gè)日期對(duì)象
    // console.log(time)
// alert(Date.parse('6 / 13 / 2019')) // 月/日/年   // 1560355200000
//     // 方法接收一個(gè)表示日期的字符串參數(shù),然后嘗試根據(jù)這個(gè)字符串返回相應(yīng)的毫秒數(shù)。

// // 如果不是標(biāo)椎的日期格式就會(huì)返回NAN。
// alert(Date.parse()); //NaN
alert('toString:' + time.toString());
alert('toLocaleString:' + time.toLocaleString()) //按本地格式輸出

toLocaleString(), toString() //這兩個(gè)方法在不同瀏覽器顯示的效果又不一樣, 但不用擔(dān)心,
// 這兩個(gè)方法只是在調(diào)試比較有用, 在顯示時(shí)間和日期上, 沒(méi)什么價(jià)值。

var time = new Date()

document.write(time.getTime()) // 獲取日期的毫秒數(shù),和valueOf()返回值一樣
document.write(time.setTime()) // 以毫秒數(shù)設(shè)置日期,會(huì)改變整個(gè)日期
document.write(time.getFullYear()) // 獲取四位年份
document.write(time.setFullYear()) // 設(shè)置四位年份,返回的是毫秒數(shù)
document.write(time.getMonth()) // 獲取月份
document.write(time.setMonth()) // 設(shè)置月份,返回的是毫秒數(shù)
document.write(time.getDate()) // 獲取日期
document.write(time.setDate()) // 設(shè)置日期,返回毫秒數(shù)
document.write(time.getDay()) //返回星期幾,0表示星期日,6表示星期六
document.write(time.setDay()) // 設(shè)置星期幾,0表示星期日,6表示星期六
document.write(time.getHours()) // 返回小時(shí)
document.write(time.getHours()) // 設(shè)置小時(shí)
document.write(time.getMinutes()) // 返回分鐘
document.write(time.setMinutes()) // 設(shè)置分鐘
document.write(time.getSeconds()) // 返回秒數(shù)
document.write(time.setSeconds()) // 設(shè)置秒數(shù)
document.write(time.getMilliseconds()) // 返回豪秒數(shù)
document.write(time.setMilliseconds()) // 設(shè)置豪秒數(shù)
最后編輯于
?著作權(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ù)。

友情鏈接更多精彩內(nèi)容