Date.prototype.getUTCMonth()

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.

getUTCMonth() 方法以世界时为标准,返回一个指定的日期对象的月份,它是从 0 开始计数的(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

语法

dateObj.getUTCMonth()

参数

无。

返回值

getUTCMonth() 返回一个 0 到 11 的整数,分别对应以下月份:0 代表一月,1 代表二月,2 代表三月,依次类推。

示例

示例:使用 getUTCMonth() 方法

下例将当前时间的月份赋值给变量 month

js
var today = new Date();
var month = today.getUTCMonth();

规范

Specification
ECMAScript® 2025 Language Specification
# sec-date.prototype.getutcmonth

浏览器兼容性

Report problems with this compatibility data on GitHub
desktopmobileserver
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
Deno
Node.js
getUTCMonth

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support

参见