Javascript Date getDay()
returns the date's day of the week as a number.
0 represents Sunday and 6 represents Saturday.
var d = new Date('December 25, 2020 23:15:30'); var weekday = d.getDay(); console.log(weekday); // 1
Return the name of the weekday:
var d = new Date(); 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);/*w w w . ja v a2 s . c o m*/
To get the full name of a day ("Monday" for example), use Intl.DateTimeFormat
.
var options = { weekday: 'long'}; var d = new Date('December 25, 2020 23:15:30'); console.log(new Intl.DateTimeFormat('en-US', options).format(d)); console.log(new Intl.DateTimeFormat('de-DE', options).format(d));