Home >Web Front-end >JS Tutorial >The JavaScript method getUTCDay() returns a number representing the day of the week based on universal time.
Definition and Usage
The getUTCDay() method returns a number representing the day of the week based on universal time.
Syntax
dateObject.getUTCDay()
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>
Output:
1
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>
Output:
Today it is Monday
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>
This will produce the following results for India time zone:
getUTCDay() : 1
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!