Skip to content
Advertisements

JavaScript Date.getDay()

Why getDay ?

The Javascript Date.getDay () method returns the day of the week according to the local time. The value returned by Date.getDay () is an integer that corresponds to the day of the week.

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

Syntax:

Date.getDay()

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


JavaScript getDay Examples

Example 1

        var date = new Date("December 05, 2019 21:55:00");
        console.log("Date.getDay() : " + date.getDay());

output:

Date.getDay() : 4


Example 2

        // now
        var date = new Date();
        console.log("Date.getDay() : " + date.getDay());

output:

Date.getDay() : 2


Example 3

        let day = new Date();
        let wake = new Array(7)
        wake[0] = "Sunday";
        wake[1] = "Monday";
        wake[2] = "Tuesday";
        wake[3] = "Wednesday";
        wake[4] = "Thursday";
        wake[5] = "Friday";
        wake[6] = "Saturday";

        let print = wake[day.getDay()];
        console.log(print)

output:

Tuesday


Browser Support

Chromeyes
Edgeyes
Firefox1
Internet Exploreryes
Operayes
Safariyes
Android webviewyes
Chrome for Androidyes
Edge mobileyes
Firefox for Android4
Opera Androidyes
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: