Date.prototype.getUTCDay()

Date 实例的 getUTCDay() 方法根据世界时间返回该日期是星期几,其中 0 代表星期日。

¥The getUTCDay() method of Date instances returns the day of the week for this date according to universal time, where 0 represents Sunday.

Try it

语法

¥Syntax

js
getUTCDay()

参数

¥Parameters

没有任何。

¥None.

返回值

¥Return value

根据通用时间,对应于给定日期的星期几的整数:0 表示星期日,1 表示星期一,2 表示星期二,依此类推。如果日期是 invalid,则返回 NaN

¥An integer corresponding to the day of the week for the given date according to universal time: 0 for Sunday, 1 for Monday, 2 for Tuesday, and so on. Returns NaN if the date is invalid.

示例

¥Examples

使用 getUTCDay()

¥Using getUTCDay()

以下示例将当前日期的工作日部分分配给变量 weekday

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

js
const today = new Date();
const weekday = today.getUTCDay();

规范

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

¥Specifications

浏览器兼容性

BCD tables only load in the browser

¥Browser compatibility

也可以看看