[英]d3.js not able to parse my string into date despite seemingly correct format? (v4)
I am using d3js v4. 我正在使用d3js v4。 The following is what my date string looks like:
以下是我的日期字符串的样子:
var ds = "2019-02-18 22:38:18.327717";
I have set up my parser like so: 我已经这样设置了解析器:
var parseDate = d3.timeParse("%Y-%m-%d %H:%M:%S.%L");
I then try and pass this string into parseDate like so: 然后,我尝试将此字符串传递给parseDate,如下所示:
var parsed_date_value = parseDate(ds);
But parsed_date_value is null after this. 但是此后parsed_date_value为null。 I figure there is some issue with the seconds part of my time format but it looks correct and I am not sure.
我认为时间格式的秒部分存在问题,但看起来正确,我不确定。 Seems to me this date string matches this format im passing to d3.timeParse()
在我看来,此日期字符串与传递给d3.timeParse()的此格式匹配
In your format string, you need to use microseconds ( %f
) instead of milliseconds ( %L
). 在格式字符串中,您需要使用微秒(
%f
)而不是毫秒( %L
)。
var parseDate = d3.timeParse("%Y-%m-%d %H:%M:%S.%f");
The complete reference is here: https://github.com/d3/d3-time-format#locale_format 完整的参考资料在这里: https : //github.com/d3/d3-time-format#locale_format
as per the documentation [ https://github.com/d3/d3-time-format] : 根据文档[ https://github.com/d3/d3-time-format] :
%L - milliseconds as a decimal number [000, 999].
%f - microseconds as a decimal number [000000, 999999].
Here my L clearly was not on the range [000,999] like required by the docs. 在这里,我的L显然不在文档所要求的[000,999]范围内。 Instead it looks to be on the range [000000, 999999] so using the following fixed it:
相反,它看起来在[000000,999999]范围内,因此使用以下命令对其进行了修复:
var parseDate = d3.timeParse("%Y-%m-%d %H:%M:%S.%f");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.