Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if the input day is Monday with moment.js

Well, I want to check if a day of date is Monday like:

var myDate = new Date();
moment(myDate, 'DD-MM-YYYY').dayIs('monday')

In my country the first day of week is Monday, so, really I want check if the input date is begin of week.

I try using moment(myDate, 'DD-MM-YYYY').startOf('isoweek') but, this don't work for me.

like image 744
Jorge Olaf Avatar asked Jan 13 '17 15:01

Jorge Olaf


1 Answers

According to the documentation - Moment.js has a locale setting which should solve this for you;

Day of Week (Locale Aware) 2.1.0+

moment().weekday(Number);

moment().weekday(); // Number

Gets or sets the day of the week according to the locale.

If the locale assigns Monday as the first day of the week, moment().weekday(0) will be Monday. If Sunday is the first day of the week, moment().weekday(0) will be Sunday.

Here you can see how to set the locale;

moment.locale('en'); // set to english

like image 156
Tom Avatar answered Oct 09 '22 04:10

Tom