Date.prototype.getUTCMonth()

Date 实例的 getUTCMonth() 方法根据世界时间返回该日期的月份,作为从零开始的值(其中零表示一年中的第一个月)。

¥The getUTCMonth() method of Date instances returns the month for this date according to universal time, as a zero-based value (where zero indicates the first month of the year).

Try it

语法

¥Syntax

js
getUTCMonth()

参数

¥Parameters

没有任何。

¥None.

返回值

¥Return value

0 到 11 之间的整数,表示根据通用时间给定日期的月份:0 代表一月,1 代表二月,依此类推。如果日期是 invalid,则返回 NaN

¥An integer, between 0 and 11, representing the month for the given date according to universal time: 0 for January, 1 for February, and so on. Returns NaN if the date is invalid.

示例

¥Examples

使用 getUTCMonth()

¥Using getUTCMonth()

以下示例将当前日期的月份部分分配给变量 month

¥The following example assigns the month portion of the current date to the variable month.

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

规范

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

¥Specifications

浏览器兼容性

BCD tables only load in the browser

¥Browser compatibility

也可以看看