我需要确定一年有多少个 ISO 周。
我的尝试看起来像这样
moment.tz(2019, "YYYY", "UTC").endOf("year").isoWeek()
但这并不能解决问题。在某些情况下,12 月 31 日是 ISO 第 1 周。
Ofc,可能有一些丑陋的方法来获得结果,但我想要一个干净的代码。
moment.js 似乎没有为此提供接口。
这似乎是解决方案(纯JS) 获取一年中的几周
在 Moment.js v2.30.1 上,您可以使用:
console.log( moment().year(2003).isoWeeksInYear()); // 52
console.log( moment().year(2004).isoWeeksInYear()); // 53
console.log( moment().year(2005).isoWeeksInYear()); // 52