JavaScript tutorial:
getDay method

 

Applies to: Date Object

The getDay method is use to get the day of the week value in a Date object using local time.

Syntax

objDate.getDay()

Return

Returns the day of the week value in a Date object using local time.

Example

To get the day using Universal Coordinated Time (UTC), use the getUTCDay method.

The value returned from the getDay method is an integer between 0 and 6 representing the day of the week and corresponds to a day of the week as follows:

0 = Sunday
1 = Monday
2 = Tuesday
3 = Wednesday
4 = Thursday
5 = Friday
6 = Saturday

The following example illustrates the use of the getDay method:

s = "Today is: ";
x = new Array("Sunday", "Monday", "Tuesday");
x = x.concat("Wednesday","Thursday", "Friday");
x = x.concat("Saturday");
d = new Date();
day = d.getDay();
s += x[day];

document.write(s);

To run the code above, paste it into JavaScript Editor, and click the Execute button

See Also: Date Object Methods, getUTCDay Method