The getUTCDay function in JavaScript retrieves the day of the week for a given date according to Coordinated Universal Time (UTC). The returned value for the day begins at 0, which signifies Sunday.
Syntax
The syntax for the getUTCDay method is as follows:
dateObj.getUTCDay()
Return
A numerical value ranging from 0 to 6 that denotes the days of the week corresponding to the given date.
JavaScript Date getUTCDay method example
In this section, we will explore the getUTCDay method by examining several examples.
Example 1
Let’s consider an example that demonstrates how to display the current day of the week based on Coordinated Universal Time (UTC).
<script>
var day=new Date();
document.writeln("Day value : "+day.getUTCDay());
</script>
Output:
Day value : 3
Example 2
Let’s examine an example that demonstrates how to display the day of the week from a specified date based on Coordinated Universal Time (UTC).
<script>
var day1=new Date("August 15, 1947 20:22:10 GMT+12:00");
var day2=new Date("August 15, 1947 20:22:10 GMT-12:00");
document.writeln("Day value : "+day1.getUTCDay()+"<br>");
document.writeln("Day value : "+day2.getUTCDay());
</script>
Output:
Day value : 5
Day value : 6