如果我有以下日期:2015-23
,格式爲%Y-%W
,即2015年第23周(2015年6月1日 - 2015年6月7日)。d3返回錯誤的星期開始
當我使用D3中的格式方法返回該周的日期:
var cameron = d3.time.format('%Y-%W').parse;
cameron('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
應該是week number of the year (Monday as the first day of the week) as a decimal number [00,53].
但它反而會提前一週!
我無法控制回來的星期幾......所以有什麼解決方案?從解析之前的星期編號只需要subrtact 1? – Cameron
您可以這樣做,或者使用其他庫/方法來獲取ISO周。 –