admin管理员组文章数量:1026062
assume this is my string in my data object
{ date: "2013-03-04 12:00:00+0000" }
var parseDate = d3.time.format("%Y-%m-%d_%H:%M:%S+%Z");
data.forEach(function(d) {
d.date = parseDate(d.date);
});
yet in my forEach
method, my date object returns null every time. I don't understand why this fails.
Similarly
{ date: "2013-03-04 00:00:00+0000" }
with
d3.time.format("%Y-%m-%d 00:00:00+00").parse
works fine. But the date is less precise because it assumes everything happens at midnight in my visualization
Why is my string date parser failing with my first scenario? I tried stepping through the date parser in console/inspect element in chrome, but to no avail.
here are the d3.time.format documents
assume this is my string in my data object
{ date: "2013-03-04 12:00:00+0000" }
var parseDate = d3.time.format("%Y-%m-%d_%H:%M:%S+%Z");
data.forEach(function(d) {
d.date = parseDate(d.date);
});
yet in my forEach
method, my date object returns null every time. I don't understand why this fails.
Similarly
{ date: "2013-03-04 00:00:00+0000" }
with
d3.time.format("%Y-%m-%d 00:00:00+00").parse
works fine. But the date is less precise because it assumes everything happens at midnight in my visualization
Why is my string date parser failing with my first scenario? I tried stepping through the date parser in console/inspect element in chrome, but to no avail.
here are the d3.time.format documents https://github./mbostock/d3/wiki/Time-Formatting
Share Improve this question asked Mar 5, 2013 at 16:49 CQMCQM 44.4k77 gold badges230 silver badges370 bronze badges 2- You might not need the [+] in [+%Z]. Try ["%Y-%m-%d_%H:%M:%S%Z"] – Andrew Commented Mar 5, 2013 at 16:55
-
@Andrew this did not work either
d3.time.format("%Y-%m-%d_%H:%M:%S%Z").parse
– CQM Commented Mar 5, 2013 at 17:22
1 Answer
Reset to default 4From the documentation page that you link to, further down:
The following directives are not yet supported for parsing:
%j - day of the year.
%U - week number of the year.
%w - weekday number.
%W - week number of the year.
%Z - time zone offset, such as "-0700".
%% - a literal "%" character.
The time zone offset you're trying to parse is not supported. The second one works because you're not trying to parse that.
If you're fine with everything being in GMT, just replace the +%Z
with +0000
in your format specification. Otherwise, you'll have to find another way of parsing dates.
assume this is my string in my data object
{ date: "2013-03-04 12:00:00+0000" }
var parseDate = d3.time.format("%Y-%m-%d_%H:%M:%S+%Z");
data.forEach(function(d) {
d.date = parseDate(d.date);
});
yet in my forEach
method, my date object returns null every time. I don't understand why this fails.
Similarly
{ date: "2013-03-04 00:00:00+0000" }
with
d3.time.format("%Y-%m-%d 00:00:00+00").parse
works fine. But the date is less precise because it assumes everything happens at midnight in my visualization
Why is my string date parser failing with my first scenario? I tried stepping through the date parser in console/inspect element in chrome, but to no avail.
here are the d3.time.format documents
assume this is my string in my data object
{ date: "2013-03-04 12:00:00+0000" }
var parseDate = d3.time.format("%Y-%m-%d_%H:%M:%S+%Z");
data.forEach(function(d) {
d.date = parseDate(d.date);
});
yet in my forEach
method, my date object returns null every time. I don't understand why this fails.
Similarly
{ date: "2013-03-04 00:00:00+0000" }
with
d3.time.format("%Y-%m-%d 00:00:00+00").parse
works fine. But the date is less precise because it assumes everything happens at midnight in my visualization
Why is my string date parser failing with my first scenario? I tried stepping through the date parser in console/inspect element in chrome, but to no avail.
here are the d3.time.format documents https://github./mbostock/d3/wiki/Time-Formatting
Share Improve this question asked Mar 5, 2013 at 16:49 CQMCQM 44.4k77 gold badges230 silver badges370 bronze badges 2- You might not need the [+] in [+%Z]. Try ["%Y-%m-%d_%H:%M:%S%Z"] – Andrew Commented Mar 5, 2013 at 16:55
-
@Andrew this did not work either
d3.time.format("%Y-%m-%d_%H:%M:%S%Z").parse
– CQM Commented Mar 5, 2013 at 17:22
1 Answer
Reset to default 4From the documentation page that you link to, further down:
The following directives are not yet supported for parsing:
%j - day of the year.
%U - week number of the year.
%w - weekday number.
%W - week number of the year.
%Z - time zone offset, such as "-0700".
%% - a literal "%" character.
The time zone offset you're trying to parse is not supported. The second one works because you're not trying to parse that.
If you're fine with everything being in GMT, just replace the +%Z
with +0000
in your format specification. Otherwise, you'll have to find another way of parsing dates.
本文标签: javascript d3js date string parsing issueStack Overflow
版权声明:本文标题:javascript d3.js date string parsing issue - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745626654a2159904.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论