Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get name of the day from date with momentjs

I am using momentjs and want to output the name of the day ie. "Wednesday" but the API only seems to offer a number.

Is there a way to do this without hard-coding it to a particular language?

like image 694
IanWatson Avatar asked Jan 07 '15 23:01

IanWatson


People also ask

How do I get weekday from date in moment?

Syntax. moment(). weekday(Number); moment(). weekday();

How do I get time from MomentJS?

The moment(). hour() Method is used to get the hours from the current time or to set the hours. moment().

Is MomentJS deprecated?

Moment construction falls back to js Date. This is discouraged and will be removed in an upcoming major release. This deprecation warning is thrown when no known format is found for a date passed into the string constructor.

Should you still use MomentJS?

Moment. js is a fantastic time & date library with lots of great features and utilities. However, if you are working on a performance sensitive web application, it might cause a huge performance overhead because of its complex APIs and large bundle size.


2 Answers

From the Format section of their documentation:

Day of Week dddd Sunday Monday ... Friday Saturday

moment().format('dddd');
like image 118
James Donnelly Avatar answered Sep 30 '22 10:09

James Donnelly


In case, if you want to get a name out of an index day

const day = 1; //second index after 0
moment().day(day).format("dddd") //Monday
like image 38
Ibrahim shamma Avatar answered Sep 30 '22 10:09

Ibrahim shamma