在两个不同的星期获得同一周 - momentjs
Getting the same week for two different weeks - momentjs
这两个日期在同一周,即使在查看日历时它们处于不同的周。我做错了什么?
moment()
.set({
year: 1982,
month: 3,
day: 21,
hour: 0,
})
.weeks()
moment()
.set({
year: 1982,
month: 3,
day: 26,
hour: 0,
})
.weeks()
两者的结果都是 17。
根据 Moment.JS 文档:
The week of the year varies depending on which day is the first day of the week (Sunday, Monday, etc), and which week is the first week of the year. For example, in the United States, Sunday is the first day of the week. The week with January 1st in it is the first week of the year.
在 1982 年的示例中,一年的第一天是星期五,这意味着每个星期五周数都会递增。因此,即使从星期日到星期六,4 月 21 日和 4 月 26 日(分别是你们的日期)在不同的星期。由于 Moment.JS 用于确定一年中的星期的语言环境,它们在技术上是同一周。
1982 年 3 月 21 日是星期日。 1982 年 3 月 26 日是星期五。如果您位于 US/Canada 或任何以星期日为一周的第一天的地方,它们在同一周内。所以你得到了正确的结果。
请参阅:https://momentjs.com/docs/#/customization/dow-doy/“一周的第一天和一年的第一周”部分下的
// ISO-8601, Europe
moment.updateLocale("en", { week: {
dow: 1, // First day of week is Monday
doy: 4 // First week of year must contain 4 January (7 + 1 - 4)
}});
// US, Canada
moment.updateLocale("en", { week: {
dow: 0, // First day of week is Sunday
doy: 6 // First week of year must contain 1 January (7 + 0 - 1)
}});
// Many Arab countries
moment.updateLocale("en", { week: {
dow: 6, // First day of week is Saturday
doy: 12 // First week of year must contain 1 January (7 + 6 - 1)
}});
// Also common
moment.updateLocale("en", { week: {
dow: 1, // First day of week is Monday
doy: 7 // First week of year must contain 1 January (7 + 1 - 1)
}});
这两个日期在同一周,即使在查看日历时它们处于不同的周。我做错了什么?
moment()
.set({
year: 1982,
month: 3,
day: 21,
hour: 0,
})
.weeks()
moment()
.set({
year: 1982,
month: 3,
day: 26,
hour: 0,
})
.weeks()
两者的结果都是 17。
根据 Moment.JS 文档:
The week of the year varies depending on which day is the first day of the week (Sunday, Monday, etc), and which week is the first week of the year. For example, in the United States, Sunday is the first day of the week. The week with January 1st in it is the first week of the year.
在 1982 年的示例中,一年的第一天是星期五,这意味着每个星期五周数都会递增。因此,即使从星期日到星期六,4 月 21 日和 4 月 26 日(分别是你们的日期)在不同的星期。由于 Moment.JS 用于确定一年中的星期的语言环境,它们在技术上是同一周。
1982 年 3 月 21 日是星期日。 1982 年 3 月 26 日是星期五。如果您位于 US/Canada 或任何以星期日为一周的第一天的地方,它们在同一周内。所以你得到了正确的结果。
请参阅:https://momentjs.com/docs/#/customization/dow-doy/“一周的第一天和一年的第一周”部分下的
// ISO-8601, Europe
moment.updateLocale("en", { week: {
dow: 1, // First day of week is Monday
doy: 4 // First week of year must contain 4 January (7 + 1 - 4)
}});
// US, Canada
moment.updateLocale("en", { week: {
dow: 0, // First day of week is Sunday
doy: 6 // First week of year must contain 1 January (7 + 0 - 1)
}});
// Many Arab countries
moment.updateLocale("en", { week: {
dow: 6, // First day of week is Saturday
doy: 12 // First week of year must contain 1 January (7 + 6 - 1)
}});
// Also common
moment.updateLocale("en", { week: {
dow: 1, // First day of week is Monday
doy: 7 // First week of year must contain 1 January (7 + 1 - 1)
}});