JAVASCRIPT

 Home  Computers & Internet  Web Programming JAVASCRIPT
What is Javascript?
Javascript Placement
Syntax
Reserved Words
Variables
Data Types
Escaping Characters
Concatenation
Arithmetic Operators
Assignment Operators
Comparison Operators
Boolean Operators
Conditional Operator
If Statements
Else If Statements
If Else Statements
Switch Statements
While Loops
For Loops
Do While Loops
Break Statement
Continue Statement
prompt()
alert()
Date()
Event Handlers
String Object Methods
Math Object Methods
Window Object Methods
Arrays

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:

getDate() getDay() getMonth()
getFullYear() getYear() getHours()
getMinutes() getSeconds() getTime()
getTimezoneOffset() parse() setDate()
setFullYear() setHours() setMinutes()
setMonth() setSeconds() setTime()
setYear() toGMTString() toLocaleString()
toString() getUTCDate() getUTCDay()
getUTCMonth() getUTCFullYear() getUTCHours()
getUTCMinutes() getUTCSeconds() getUTCMilliseconds()
setUTCDate() setUTCDay() setUTCMonth()
setUTCFullYear() setUTCHour() setUTCMinutes()
setUTCSeconds() setUTCMilliseconds()  
Home | Privacy Policy | Terms Of Use | Contact Us