Date .timeFormat(%b%Y)没有为我提供正确的日期

Date .timeFormat(%b%Y)没有为我提供正确的日期,date,d3.js,formatting,Date,D3.js,Formatting,我是d3.js的初学者。现在的目标是将日期列从“2018-11-01”改为“11月18日”。 日期从“2016-11-01”开始到“2020-08-01”,中间的每个日期仅为每个月的第一天 例如: "2016-11-01", "2016-12-01", "2017-01-01", "2017-02-01", "2017-03-01", "2017-04-01", "

我是d3.js的初学者。现在的目标是将日期列从“2018-11-01”改为“11月18日”。 日期从“2016-11-01”开始到“2020-08-01”,中间的每个日期仅为每个月的第一天

例如:

"2016-11-01", 
"2016-12-01",
"2017-01-01",
"2017-02-01",
"2017-03-01",
"2017-04-01",
"2017-05-01",
我使用的代码如下:

        var format = d3.timeFormat("%b %Y");    
        var data = d3.dsv(",", dsvPath, function (d) {
            return {
                //Year : getYear(new Date(+d.year,0,1)),
                
                date: format(new Date(d.date)),
                ['Catan=count']:+d['Catan=count'],
                ['Dominion=count']:+d['Dominion=count'],
                ['Codenames=count']:+d['Codenames=count'],
                ['Terraforming Mars=count']:+d['Terraforming Mars=count'],
                ['Gloomhaven=count']:+d['Gloomhaven=count'],
                ['Magic: The Gathering=count']:+d['Magic: The Gathering=count'],
                ['Dixit=count']:+d['Dixit=count'],
                ['Monopoly=count']:+d['Monopoly=count']
                //['Running Total'] : +d["running_total"]
            };
        }).then(function (data) {
            
            console.log(data[0]); 
            minDate = d3.min(data,function(d){console.log(d); return d.date;});
            maxDate = d3.max(data,function(d){console.log(d); return d.date;});
            console.log(minDate);
然而,对于最短日期,我得到的是2017年4月,而不是2016年11月。最长日期为2020年5月,而不是2020年9月

当我按原样读取数据而不使用数据格式时,minDate和maxDate是正确的。然而,一旦我格式化,数据集中不存在的2016年10月就会以某种方式记录两次

此外,控制台中的数据停止在“2020年7月”:没有2020年8月和9月。我真的很困惑

任何帮助都将不胜感激!
谢谢大家!

通过
Date()
构造函数转换为日期是出了名的棘手。谢天谢地,由于D3为我们提供了从日期到字符串,从字符串到日期的方法。

我们的进程将是双重的:

  • 对于特定格式的每个字符串,使用
    d3.timeParse()
    转换为
    Date
  • 将每个日期转换为所需的字符串格式
  • (1.)(2.)
    "2016-01-01"