为什么当我指定第一天为星期一时,moment.weekdays()返回从星期日开始的日期? [英] Why moment.weekdays() returns days starting with Sunday when I specified that first day is Monday?

查看:1977
本文介绍了为什么当我指定第一天为星期一时,moment.weekdays()返回从星期日开始的日期?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将语言环境设置为'ro',现在工作日为罗马尼亚语. 但是,我还设置了

I set the locale to 'ro' and now weekdays are in romanian. But, I also set the

week : {
    dow : 1
}

moment.weekdays()返回与'en'中相同的天,从星期日开始.为什么会这样?

and moment.weekdays() returns days as in 'en' starting with Sunday. Why is this happening?

推荐答案

您必须使用moment.weekdays(true);

文档指出:

2.13.0 开始,您可以将布尔值作为工作日函数的第一个参数传递.如果为true,则将按特定于语言环境的顺序返回工作日.例如,在阿拉伯语区域中,星期六是一周的第一天

As of 2.13.0 you can pass a bool as the first parameter of the weekday functions. If true, the weekdays will be returned in locale specific order. For instance, in the Arabic locale, Saturday is the first day of the week

这里有个例子:

moment.locale('ro');
// duminică to sâmbătă
console.log(moment.weekdays());
// locale aware: luni to duminică
console.log(moment.weekdays(true));

<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.18.1/moment-with-locales.min.js"></script>

这篇关于为什么当我指定第一天为星期一时,moment.weekdays()返回从星期日开始的日期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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