Javascript - Date getDay() Method

The getDay() method returns the day of the week (from 0 to 6) from the date object.

Description

The getDay() method returns the day of the week (from 0 to 6) from the date object.

Sunday is 0, Monday is 1, and so on.

Syntax

Date.getDay()

Parameters

None

Return

A Number, from 0 to 6, representing the day of the week

Example

Return the day of the week:

Demo

//display todays day of the week.
var d = new Date();
var n = d.getDay()
console.log(n);// www .j  a v a2s.c om

//Return the name of the weekday (not just a number):

//display todays day of the week.
var weekday = new Array(7);
weekday[0] = "Sunday";
weekday[1] = "Monday";
weekday[2] = "Tuesday";
weekday[3] = "Wednesday";
weekday[4] = "Thursday";
weekday[5] = "Friday";
weekday[6] = "Saturday";

var n = weekday[d.getDay()];
console.log(n);

Result