Return the name of the weekday in UTC - Javascript Date

Javascript examples for Date:getUTCDay

Description

Return the name of the weekday in UTC

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<button onclick="myFunction()">Test</button>

<p id="demo"></p>

<script>
function myFunction() {//from w  ww  .  j av a 2s .  c om
    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>

<p><strong>Note:</strong> 0=Sunday, 1=Monday, etc.</p>

</body>
</html>

Related Tutorials