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 | 
浏览器兼容性
加载中…