JavaScript Date getUTCDay() Method



The JavaScript Date.getUTCDay() method is used to retrieve the "day of the week" for a date according to Coordinated Universal Time (UTC). The returned value will represent the day of the week as an integer value between 0 to 6, where 0 represents sunday, 1 to monday, 2 to tuesday,..., and 6 to saturday. Additionally, this method does not accept any parameters.

This method does returns Not a Number (NaN), if the provided date is invalid date.

Syntax

Following is the syntax of JavaScript Date getUTCDay() method −

getUTCDay();

This method does not accept any parameters.

Return Value

An integer representing the day of the week in UTC time zone.

Example 1

Following is the basic example of JavaScript Date getUTCDay() method −






Output

It returns the "day of week" according to UTC.

Example 2

In the following example, we are providing a specific date to the date constructor −






Output

The above program retrieves "3" as the day of the week.

Example 3

This example uses a function, getDayName(), to get the day name based on the day index. It then displays the current day of the week in UTC using this function.






Output

It returns the current day of week according to UTC.

Advertisements