試一試
const birthday = new Date("August 19, 1975 23:15:30");
const date = birthday.getDate();
console.log(date);
// Expected output: 19
語法
js
getDate()
引數
無。
返回值
返回一個介於 1 和 31 之間的整數,表示給定日期在本地時間中的月份的“日”。如果日期 無效,則返回 NaN。
示例
使用 getDate()
根據 Date 物件 xmas95 的值,變數 day 的值為 25。
js
const xmas95 = new Date("1995-12-25T23:15:30");
const day = xmas95.getDate();
console.log(day); // 25
規範
| 規範 |
|---|
| ECMAScript® 2026 語言規範 # sec-date.prototype.getdate |
瀏覽器相容性
載入中…