Date.prototype.getUTCHours()

Date 实例的 getUTCHours() 方法根据世界时间返回该日期的小时数。

¥The getUTCHours() method of Date instances returns the hours for this date according to universal time.

Try it

语法

¥Syntax

js
getUTCHours()

参数

¥Parameters

没有任何。

¥None.

返回值

¥Return value

0 到 23 之间的整数,表示根据通用时间给定日期的小时数。如果日期是 invalid,则返回 NaN

¥An integer, between 0 and 23, representing the hours for the given date according to universal time. Returns NaN if the date is invalid.

示例

¥Examples

使用 getUTCHours()

¥Using getUTCHours()

以下示例将当前时间的小时部分分配给变量 hours

¥The following example assigns the hours portion of the current time to the variable hours.

js
const today = new Date();
const hours = today.getUTCHours();

规范

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

¥Specifications

浏览器兼容性

BCD tables only load in the browser

¥Browser compatibility

也可以看看