Javascript method to get day of week from string?

Let's say I have a line like the following: 2013-11-22T08:50:33+0000 What does it meanFriday, November 2013, 8:50:33.

How can I say that on Friday he received a string?

+4
source share
1 answer

You would use date.getDay()to get the day as a number, and then you would use a map, array, or anything else that you would like to match this number per day

var day = new Date("2013-11-22T08:50:33+0000").getDay(); // returns 5

so you can do something like:

var s = "2013-11-22T08:50:33+0000" 

var days = [
    'Sunday',
    'Monday',
    'Tuesday',
    'Wednesday',
    'Thursday',
    'Friday',
    'Saturday'
]

var d = days[new Date(s).getDay()]; // Friday

Fiddle

+5
source

All Articles