JavaScript getUTCDay() method

In JavaScript the method getUTCDay() returns a number between 0-6 inclusive and these numbers represent the day of the week according to the Universal Coordinated Time (UTC).

JavaScript getUTCDay() method

JavaScript getUTCDay() method

     

In JavaScript the method getUTCDay() returns a number between 0-6 inclusive and these numbers represent the day of the week according to the Universal Coordinated Time (UTC). In the following list we have provided you the week day according to the numbers as follows:

Number  Day
0 Sunday
1 Monday
2 Tuesday
3 Wednesday
4 Thursday
5 Friday
6 Saturday

Syntax:

 Date_object.getUTCDay();

Where Date_object is the Date object that we required to call the getUTCDay() method. In the following example we will describe you how to use getUTCDay() method.

Description of code:

To illustrate the use of getUTCDay() method we have created a simple button into a HTML page and this button when clicked calls the user defined function getUTCDayFunc() which is defined in the JavaScript ( in <script> tags).

 
 function getUTCDayFunc(){
		  var myDate = new Date(); 
	    	  alert(myDate.getUTCDay());
	    }

In the above lines of code we have taken the date object into variable myDate and now further we will use this date object for finding the UTC day of the week on the particular date.

Here is the full HTML code, which illustrates the use of getUTCDay() method :

<html>
<head>
	<title>Get UTC day example</title>
	<script>
	function getUTCDayFunc(){
			var myDate = new Date(); 
	    	alert(myDate.getUTCDay());
	    	}
	</script>	
</head>
<body>
<div style="background: #335556; width:'100%';" 
   align="center">
  <font color="#ffddff" size="12pt">
	<b>Get UTC day example</b>
  </font>
 </div>
  <center>
  <p>&nbsp;</p>
  <input type="button" onclick="getUTCDayFunc();"
        value="Show UTC day">
</center>
</body>
</html>

Output :

When user clicks on the button "Show UTC day" it returns a number between 0-6. For example in our case it returned 3 which represents "wednesday".

You can also download the full code from the following link.

Download Source Code