简体   繁体   English

使用d3.js格式化日期/时间

[英]Format date / time with d3.js

I have the following date format: 1/6/2014 7:28 . 我具有以下日期格式: 1/6/2014 7:28

I want to plot this along with other dates in the same format along the x-axis of a d3.js graph. 我想沿着d3.js图的x轴以相同格式绘制此日期和其他日期。

I am using var format = d3.time.format('%m-%d-%Y %H:%M').parse; 我正在使用var format = d3.time.format('%m-%d-%Y %H:%M').parse; but the console just returns null , 但是控制台仅返回null

After the call to the data I am doing 调用数据后,我正在做

data.forEach(function(d) {
    d.timestamp = format(d.timestamp);
});

Am I doing this the correct way? 我这样做正确吗?

Thanks 谢谢

The format string you specified does not match the format of the date you are trying to parse. 您指定的格式字符串与您尝试解析的日期的格式不匹配。 In particular the separators are different. 特别是分隔符是不同的。

Try this: 尝试这个:

var format = d3.time.format('%m/%d/%Y %H:%M').parse;

Instead of: 代替:

var format = d3.time.format('%m-%d-%Y %H:%M').parse;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM