JavaScript getUTCDay Method





The getUTCDay method returns, according to universal time, the day of the week of the point in time stored in a Date object. The value returned by this method is an integer number from 0 to 6, zero being Sunday and six being Saturday.


Syntax

myDate.getUTCDay()

With myDate being an object based on the Date object.


Example

The following code uses the getUTCDay method to return, according to universal time, the day of the week of the current date stating its number and name:

<script type="text/javascript">

function getDayName(dayNumber)
{
  var dayNames = new Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
  
  return dayNames[dayNumber];
}

var currentDate = new Date();
var universalDayOfTheWeek = currentDate.getUTCDay();
var nameOfTheDay = getDayName(universalDayOfTheWeek);

document.write("According to universal time the number of the current day of the week is " + universalDayOfTheWeek + ", which means it is " + nameOfTheDay + ".");

</script>


Technical Details

The getUTCDay method belongs to the Date object, it is available since the version 1.3 of JavaScript, and it is supported in all major browsers.





JavaScript Manual >> Date Object >> getUTCDay Method





© Copyright 2010-2016 ROM Cartridge