Date.prototype.getUTCMonth()
getUTCMonth() 方法用於 Date 例項,根據世界協調時間(UTC)返回月份,返回值為 0 到 11 的整數(其中 0 表示一年中的第一個月)。
試一試
const date1 = new Date("December 31, 1975, 23:15:30 GMT+11:00");
const date2 = new Date("December 31, 1975, 23:15:30 GMT-11:00");
// December
console.log(date1.getUTCMonth());
// Expected output: 11
// January
console.log(date2.getUTCMonth());
// Expected output: 0
語法
js
getUTCMonth()
引數
無。
返回值
一個介於 0 和 11 之間的整數,表示根據世界協調時間(UTC)的給定日期的月份:0 代表一月,1 代表二月,以此類推。如果日期 無效,則返回 NaN。
示例
使用 getUTCMonth()
下面的示例將當前日期的月份部分賦給變數 month。
js
const today = new Date();
const month = today.getUTCMonth();
規範
| 規範 |
|---|
| ECMAScript® 2026 語言規範 # sec-date.prototype.getutcmonth |
瀏覽器相容性
載入中…