| Viewed 60 times

How to Get the Date in JavaScript?


I need a function that, given a date (in the format MM/DD/YYYY), returns the day of the week as a string. Each day name must be one of the following strings: "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", or "Saturday". To illustrate, the day of the week for "12/07/2016" is "Wednesday".

1 Answer
Mohammad Qandeel
Answered
10

look to this function its returns the day of the week as a string

function getDay(day) {
 let d = new Date(day)
 let days = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]
 return days[d.getDay()]
}

Example

getDay(1/07/2019) // "Thursday"

 


Related Questions