|
| JAVASCRIPT getUTCMonth() METHOD
The getUTCMonth() method in javascript returns the month in UTC (Universal Coordinated Time) as an integer from 0 through 11. January has a value of 0 through to December which has a value of 11.
The general format is:
dateObject.getUTCMonth();
If you want to return the month with getUTCMonth() method, you will first have to create a new date object and then use the new date object with the getUTCMonth() method.
Example 1: Using getUTCMonth() for this month:
<script type="text/javascript">
var mm=new Date(); // creates new date object
mm=mm.getUTCMonth(); // returns the month
doument.write(mm); // outputs the month
</script>
The above will output:
Example 2: Using getUTCMonth() to get month of specified date:
<script type="text/javascript">
var mm=new Date("December 16, 2005 20:06:25");
mm=mm.getUTCMonth();
doument.write(mm);
</script>
The above will output:
Example 3: Using getUTCMonth() and a switch statement to get the name of the month:
<script type="text/javascript">
var mm=new Date();
mm=mm.getUTCMonth();
switch(mm)
{
case (0):
var MON="January";
break;
case (1):
var MON="February";
break;
case (2):
var MON="March";
break;
case (3):
var MON="April";
break;
case (4):
var MON="May";
break;
case (5):
var MON="June";
break;
case (6):
var MON="July";
break;
case (7):
var MON="August";
break;
case (8):
var MON="September";
break;
case (9):
var MON="October";
break;
case (10):
var MON="November";
break;
case (11):
var MON="December";
break;
}
document.write(MON);
</script>
The above outputs:
See Also:
|
|