2

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.com/mbostock/d3/wiki/Time-Formatting

2
  • You might not need the [+] in [+%Z]. Try ["%Y-%m-%d_%H:%M:%S%Z"] Commented Mar 5, 2013 at 16:55
  • @Andrew this did not work either d3.time.format("%Y-%m-%d_%H:%M:%S%Z").parse Commented Mar 5, 2013 at 17:22

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

this did not work d3.time.format("%Y-%m-%d_%H:%M:%S+0000").parse
this worked d3.time.format("%Y-%m-%d %H:%M:%S+0000").parse thanks, took a lot of trial and error. The documents suggest that _ is needed for a space, but that was misleading

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.