gpt4 book ai didi

javascript - d3 返回不正确的星期开始

转载 作者:行者123 更新时间:2023-11-30 15:45:07 25 4
gpt4 key购买 nike

如果我有以下日期:2015-23,格式为 %Y-%W,即 2015 年第 23 周(2015 年 6 月 1 日 - 2015 年 6 月 7 日) ).

当我使用 d3 中的格式方法返回那一周的日期时:

var cameron = d3.time.format('%Y-%W').parse;

卡梅伦('2015-23');

它返回 Mon Jun 08 2015 00:00:00 GMT+0100 (BST)

但我应该得到:Mon Jun 01 2015 00:00:00 GMT+0100 (BST)

根据文档:https://github.com/d3/d3-3.x-api-reference/blob/master/Time-Formatting.md %W 应该是 一年中的周数(星期一作为一周的第一天)作为十进制数 [00,53]。 但是它向前跳了一周!

最佳答案

这是预期的结果。根据 Mike Bostock 的说法:

The %W directive used by d3-time-format is not the ISO week date; it is the zero-based Monday-of-year in [00, 53]. This means that the first Monday in any given year is always number 1; any date prior to this first Monday in the same year is 0.

“ISO 星期日期”,他的意思是这个 (ISO 8061):https://en.wikipedia.org/wiki/ISO_week_date

所以,还是按照他的说法:

  • 2015-00 是 2014 年 12 月 29 日,星期一。
  • 2015-01 是 2015 年 1 月 5 日,星期一。
  • 2015-52 和 2016-00 是 2015 年 12 月 28 日,星期一。
  • 2015-53 和 2016-01 是 2016 年 1 月 4 日,星期一。

关于javascript - d3 返回不正确的星期开始,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40178712/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com