Home > Web Front-end > JS Tutorial > The JavaScript method getUTCDay() returns a number representing the day of the week based on universal time.

The JavaScript method getUTCDay() returns a number representing the day of the week based on universal time.

黄舟
Release: 2017-11-06 13:16:55
Original
1618 people have browsed it

Definition and Usage

The getUTCDay() method returns a number representing the day of the week based on universal time.

Syntax

dateObject.getUTCDay()
Copy after login

Return value

dateObject When expressed in universal time, returns a day of the week, the value is 0 (Sunday) ~ 6 (Saturday) a value.

Tips and Notes:

Note: This method is always used in conjunction with a Date object.

Tip: For more information about Universal Coordinated Time (UTC), please refer to Baidu Encyclopedia.

Example

Example 1

In this example, we will get the current UTC day of the week (as a number):

<script type="text/javascript">

var d=new Date()
document.write(d.getUTCDay())

</script>
Copy after login

Output:

1
Copy after login

Example 2

Now, I will create an array so that the above example can output the name of the week instead of just a number:

<script type="text/javascript">

var d=new Date()

var weekday=new Array(7)
weekday[0]="Sunday"
weekday[1]="Monday"
weekday[2]="Tuesday"
weekday[3]="Wednesday"
weekday[4]="Thursday"
weekday[5]="Friday"
weekday[6]="Saturday"

document.write("Today it is " + weekday[d.getUTCDay()])

</script>
Copy after login

Output:

Today it is Monday
Copy after login

The javascript Date.getUTCDay() method returns the day of the week on the specified date according to universal time. The value returned by getUTCDay is an integer corresponding to the day of the week: 0 for Sunday, 1 for Monday, 2 for Tuesday, and so on.

Example:

<html>
<head>
<title>JavaScript getUTCDay Method</title>
</head>
<body>
<script type="text/javascript">
  var dt = new Date( "December 25, 1995 23:15:20" );
  document.write("getUTCDay() : " + dt.getUTCDay() ); 
</script>
</body>
</html>
Copy after login

This will produce the following results for India time zone:

getUTCDay() : 1
Copy after login

The above is the detailed content of The JavaScript method getUTCDay() returns a number representing the day of the week based on universal time.. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template