javascript d3.js date string parsing issue - Stack Overflow

assume this is my string in my data object{ date: "2013-03-04 12:00:00+0000" }var parseDate =

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
Add a ment  | 

1 Answer 1

Reset to default 4

From 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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745626656a4636849.html

相关推荐

  • javascript d3.js date string parsing issue - Stack Overflow

    assume this is my string in my data object{ date: "2013-03-04 12:00:00+0000" }var parseDate =

    7小时前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信