[英]Change start of the week to Monday
I am trying to follow this tutorial . 我正在尝试按照本教程 。
It builds a calendar where Sunday is the first day of the week. 它构建了一个日历,其中星期日是一周的第一天。 I don't completely grok how it works, honestly.
老实说,我并不完全了解它是如何运作的。 What I cannot understand is how to make it show a calendar where week starts from Monday, not Sunday.
我无法理解的是如何让它显示一个日历,从星期一开始,而不是星期日。 I think the problem is somewhere in this line:
我认为问题出在这一行:
date = this.state.month.clone().startOf("month").add("w" - 1).day(0),
I tried day(1)
, then it builds weeks starting from Monday, but if the 1st day of the month is Sunday, then it leaves this day on the screen of the previous month, showing the current one starting from the 2nd day: 我尝试了
day(1)
,然后它从星期一开始建立周,但是如果该月的第一天是星期日,那么它将在上个月的屏幕上离开这一天,从第二天开始显示当前的一天:
How can I do this? 我怎样才能做到这一点?
I got it to at least render the current month properly with 我得到它至少正确地渲染当前月份
date = this.state.month.clone().startOf("month").add("w" -1).day(1),
as you mentioned, along with rearranging the day of the week labels 正如您所提到的,同时重新排列星期几的标签
var DayNames = React.createClass({
render: function() {
return <div className="week names">
<span className="day">Mon</span>
<span className="day">Tue</span>
<span className="day">Wed</span>
<span className="day">Thu</span>
<span className="day">Fri</span>
<span className="day">Sat</span>
<span className="day">Sun</span>
</div>;
}
});
Fiddle: https://jsfiddle.net/yy33bmze/3/ 小提琴: https : //jsfiddle.net/yy33bmze/3/
OK, I got it. 好,我知道了。 Instead of trying to get explicit day as start of the week,
startOf('isoWeek')
should be used. 应该使用
startOf('isoWeek')
,而不是试图将明确的一天作为一周的开始。 So instead of 而不是
date = this.state.month.clone().startOf("month").add("w" - 1).day(0),
I did: 我做了:
date = this.state.month.clone().startOf("month").add("w"-1).startOf('isoWeek'),
and now it looks right: 现在它看起来正确:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.