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ù)