好吧,我想检查日期是否是星期一,例如:
var myDate = new Date();
moment(myDate, 'DD-MM-YYYY').dayIs('monday')
在我的国家,一周的第一天是星期一,所以,我真的想检查输入日期是否是一周的开始。
我尝试使用 moment(myDate, 'DD-MM-YYYY').startOf('isoweek')
但是,这对我不起作用。
最佳答案
According to the documentation - Moment.js 有一个区域设置,应该可以为您解决这个问题;
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');//设置为英语
关于javascript - 使用 moment.js 检查输入日期是否为星期一,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41638428/