How to use getUTCday in JavaScript

In this article, I will explain use of getUTCday() method in JavaScript date object.
  • 1694

JavaScript date getUTCday() method

  • getUTCday() method of date object returns the day of the week for the specified date according to UTC.

  • In getUTCday() method, The returned value is an integer corresponding to the day of the week. as like 0 for Sunday, 1 for Monday, 2 for Tuesday, and so on.

  • UTC is  The Universal Coordinated Time. UTC time is the same as GMT time

Syntax

Date.getUTCday()

Example

In the following example show to getUTCday() method returns the day of the week of a given date and current date according to UTC.

<!DOCTYPE html>

<html>

<body>

<h3 style="color:ActiveCaption ">JavaScript getUTCDay() Method Example</h3>

<p id="demo">Click for display the day of the week, according to UTC.</p>

<button onclick="myFunction()">Try it</button>

<script type="text/javascript">

    function myFunction() {

        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 x = document.getElementById("demo");

        document.write("Current UTC day is: " + weekday[d.getUTCDay()]);

    }

</script>

</body>

</html>

Output1

getUTCDay 1.jpg

Output2

getUTCDay 2.jpg

You may also want to read these related articles here

Ask Your Question 

Got a programming related question? You may want to post your question here

Programming Answers here

Categories

More Articles

© 2020 DotNetHeaven. All rights reserved.