moment.js认为2013-12-31是第1周,而不是第53周 [英] moment.js thinks that 2013-12-31 is week 1, not week 53

查看:420
本文介绍了moment.js认为2013-12-31是第1周,而不是第53周的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

moment.js库真棒,我几乎一直都在使用它,但最近我碰到了一些有趣的东西。我试图在一年中的每周绘制数据,其中一个数据点是2013-12-31,moment.js告诉我这是第1周?有没有更好的方法来处理这个?是53,null,-1还是其他什么?

The moment.js library is awesome, and I use it almost all the time, but I recently ran into something interesting. I'm trying to plot data by week of the year, and one of the data points was 2013-12-31, moment.js tells me this is week 1? Is there a better way to handle this? either with 53, null, -1, or something?

moment('2013-12-31').week()
(returns) 1

我想也许使用isoWeek或格式可以解决这个问题,但是它们都返回相同的值1,尽管文档称其为53.

I thought maybe using isoWeek or format would get around this, but they all return the same value of 1, despite the documentation saying it goes to 53.

moment('2013-12-31').isoWeek()
(returns) 1
+moment('2013-12-31').format('w')
(returns) 1   

任何人对此都有任何想法? (除了测试计算周数是否有一个涵盖我通过它的日期值的最小/最大日期)

Anyone have any ideas on this? (short of making a test whether the week computed has a min/max date that covers the date value I passed it)

推荐答案

这是因为2013年12月30日这一周被认为是2014年的第一周,你可能会在这个页面上看到 epoch转换器

It is because the week from the 30th december 2013 is considered to be the 1st week of 2014 as you may see on this page epoch converter

根据momentjs 文档

And according to momentjs documentation:


1月1日的一周这是一年中的第一周。

The week with January 1st in it is the first week of the year.

这篇关于moment.js认为2013-12-31是第1周,而不是第53周的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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