日期對象?
作用:用來表示時間的對象
獲取當前時間
const date=new Date();console.log(date);
可以得到日期對象,里面的屬性有星期,年月日,時分秒?
獲取指定時間
const date=new Date('2023-05-01');console.log(date);
?
獲取時間戳
時間戳是自從1970年1月1日的午夜開始到現在流過的毫秒數
const date=+new Date();console.log(date);
?
?
日期對象方法?
方法 | 作用 |
---|---|
getFullYear() | 獲取四位數年份 |
getMonth() | 獲得月份,取值為0~11 |
getDate() | 獲取月份中的天數,一個月有多少天 |
getDay() | 獲取星期,取值為0~6 |
getHours() | 獲取小時,取值為0~23 |
getMinutes() | 獲取分數,取值為0~59 |
getSeconds() | 獲取秒,取值為0~59 |
?