使用moment.js检查输入日是否为星期一 [英] Check if the input day is Monday with moment.js

查看:1114
本文介绍了使用moment.js检查输入日是否为星期一的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,我想查看星期一的日期是否如下:

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.

我尝试使用时刻($ scope.myDate,'DD-MM-YYYY')。startOf('isoweek')但是,这不是为我工作。

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

推荐答案

根据文档 - Moment.js有一个区域设置,应该为你解决这个问题;

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


星期几(Locale Aware)2.1.0 +

Day of Week (Locale Aware) 2.1.0+

moment()。weekday(Number);

moment()。weekday(); //数字

根据区域设置获取或设置星期几。

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

如果语言环境将星期一指定为一周的第一天,则moment()。weekday(0)将是星期一。如果星期日是一周的第一天,则星期()。星期日(0)将是星期日。

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.

在这里,您可以看到如何设置区域设置;

moment.locale('en'); //设为英语

这篇关于使用moment.js检查输入日是否为星期一的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆