Check if the input day is Monday with moment.js

泄露秘密 提交于 2019-12-07 07:22:35

问题


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

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

In Chile - 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($scope.myDate, 'DD-MM-YYYY').startOf('isoweek') but, this don't work for me.


回答1:


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



来源:https://stackoverflow.com/questions/41638428/check-if-the-input-day-is-monday-with-moment-js

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!