![]() |
VOOZH | about |
JavaScript Date getDay() Method is used to fetch the day of a week(0 to 6) from a given Date object.
DateObj.getDay()Example 1: In this example, we will write a simple program to get the number of day of the week using getDay().
Output:
Number of Day: 2Example 2: If the date of the month is not given, by default the function considers it as the first date of the month and hence accordingly it returns the day of the week. It is an exceptional case.
Output:
Number of Day: 1Example 3: The date of the month should lie between 1 to 31 because none of the months have a date greater than 31 that is why it returns NaN i.e, not a number because the date for the month does not exist.
Output:
NaNExample 4: If nothing as a parameter is given, it returns the current day of the current week.
Output: It returns the current day of the week.
5The browsers supported by JavaScript Date.getDay() method are listed below: