|
| JAVASCRIPT getUTCDay() METHOD
The getUTCDay() method in javascript returns the day of the week in UTC (Universal Coordinated Time) as an integer from 0 through 6. Sunday has a value of 0 through to Saturday which has a value of 6.
The general format is:
dateObject.getUTCDay();
If you want to return the day of the week with getUTCDay() method, you will first have to create a new date object and then use the new date object with the getUTCDay() method.
Example 1: Using getUTCDay() for today:
<script type="text/javascript">
var dd=new Date(); // creates a new date object
dd=dd.getUTCDay(); // returns the day of the week
document.write(dd); // outputs the day of the week
</script>
The above will output:
Example 2: Using getUTCDay() to get day of week of a specified date:
<script type="text/javascript">
var dd=new Date("January 16, 2008 21:00:05");
dd=dd.getUTCDay();
document.write(dd);
</script>
The above will output:
Example 3: Using getUTCDay() and a switch statement to get the name of the day:
<script type="text/javascript">
var dd=new Date();
dd=dd.getUTCDay();
switch(dd)
{
case (0):
var DAY="Sunday";
break;
case (1):
var DAY="Monday";
break;
case (2):
var DAY="Tuesday";
break;
case (3):
var DAY="Wednesday";
break;
case (4):
var DAY="Thursday";
break;
case (5):
var DAY="Friday";
break;
case (6):
var DAY="Saturday";
break;
}
document.write(DAY);
</script>
The above outputs:
See Also:
|
|