Home Javascript JavaScript getUTCDay() method
Questions:Ask|Latest

 
 

Share on Google+Share on Google+

JavaScript getUTCDay() method

Advertisement
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

     

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

     

Advertisements

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: February 7, 2009

Related Tutorials

Ask Questions?    Discuss: JavaScript getUTCDay() method  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
DMCA.com