Javascript Reference - JavaScript getUTCDay() Method








getUTCDay()
Returns the UTC date's day of the week as a number (where 0 represents Sunday and 6 represents Saturday).

Sunday is 0, Monday is 1, and so on.

UTC time is the same as GMT time.

Browser Support

getUTCDay() Yes Yes Yes Yes Yes

Syntax

dateObject.getUTCDay();

Parameters

None.





Return Value

return a number, from 0 to 6, representing the day of the week.

Example


var myDate = new Date();
console.log(myDate.getUTCDay());

The code above generates the following result.

Example 2

The following code returns the name of the weekday defined in an array.


<!DOCTYPE html>
<html>
<body>
<button onclick="myFunction()">test</button>
<p id="demo"></p>
<script>
function myFunction() {<!--   w w w .  j  ava2  s.co m-->
    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";

    var n = weekday[d.getUTCDay()];
    document.getElementById("demo").innerHTML = n;
}
</script>
</body>
</html>

The code above is rendered as follows: