The getDay method returns 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.getDay()
With myDate being an object based on the Date object.
Instead of being instantiated from a class, in JavaScript objects are created by replicating other objects. This paradigm is called Prototype-based programming.
Example
The following code uses the getDay method to return 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 dayOfTheWeek = currentDate.getDay();
var nameOfTheDay = getDayName(dayOfTheWeek);
document.write("The number of the current day of the week is " + dayOfTheWeek + ", which means it is " + nameOfTheDay + ".");
</script>
function getDayName(dayNumber)
{
var dayNames = new Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
return dayNames[dayNumber];
}
var currentDate = new Date();
var dayOfTheWeek = currentDate.getDay();
var nameOfTheDay = getDayName(dayOfTheWeek);
document.write("The number of the current day of the week is " + dayOfTheWeek + ", which means it is " + nameOfTheDay + ".");
</script>
Technical Details
The getDay method belongs to the Date object, it is available since the version 1.0 of JavaScript, and it is supported in all major browsers.
JavaScript Manual >> Date Object >> getDay Method