javascript - 使用 moment.js 检查输入日期是否为星期一

标签 javascript momentjs

好吧,我想检查日期是否是星期一,例如:

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/

相关文章:

javascript - 为什么 BST(英国夏令时/夏令时)被添加到我的 Node 日期时间中?

momentjs - 使用Moment.js按月份名称获取月份号

javascript - 你能用 Moment.js 从日期字符串中获取日期格式模式吗

javascript - 使用 moment-hijri.js 调整伊斯兰日期

javascript - 在Javascript中,如何将字符串转换为属性名称?

javascript - meteor DOMException : Unable to decode audio data

javascript - 使用 Javascript/jQuery 计算字符数

javascript - webpack-dev-server 不监视创建的新文件

angular - 如何测试使用 moment 的 angular2 服务?

javascript - 模态打开时在 Bootstrap 模态窗口中自动播放视频