[英]d3.js date time format specifier not working as expected
I am using the below format specifier for dealing with datetime inputs in my d3.js force directed graph 我正在使用以下格式说明符来处理d3.js强制有向图中的日期时间输入
var parseDate = d3.timeFormat("%Y-%m-%d %H:%M:%S")
Below is an example of how the datetime data is in my graph. 以下是日期时间数据在我的图形中的示例。 But 但
console.log(parseDate('2015-1-7 13:45:54'))
gives the following output: 给出以下输出:
0NaN-NaN-NaN NaN:NaN:NaN
Is there anything additional that needs to be done with the input? 输入是否还有其他需要完成的工作?
What you might be looking for is d3.timeParse()
您可能正在寻找的是d3.timeParse()
var parseDate = d3.timeParse("%Y-%m-%d %H:%M:%S")
console.log(parseDate('2015-1-7 13:45:54'))
You have to pass a Date object to the parseDate
function: 您必须将Date对象传递给parseDate
函数:
var parseDate = d3.timeFormat('%Y-%m-%d %H:%M:%S');
// method 1 (month is zero-based)
console.log(parseDate(new Date(2015, 0, 7, 13, 45, 54)));
// method 2
console.log(parseDate(new Date('2015-1-7 13:45:54')));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.