Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

D3.js utcParse() returns null

I've got a date format which looks like this: 2017-02-18T09:00:00+06:00.

This is the format I'm trying to parse it with: d3.utcParse("%Y-%m-%dT%H:%M:%S+%Z");, but it returns null.

Any ideas? Thanks!

like image 885
hanserino Avatar asked May 07 '26 20:05

hanserino


2 Answers

Instead of

d3.utcParse("%Y-%m-%dT%H:%M:%S+%Z");//+ is not needed

It should have been

d3.utcParse("%Y-%m-%dT%H:%M:%S%Z")

working code here

like image 165
Cyril Cherian Avatar answered May 10 '26 18:05

Cyril Cherian


Your parsing specifier is not correct. The + in the timezone +06:00 is actually part of the timezone and must not be included in the specifier string.

var parser = d3.utcParse("%Y-%m-%dT%H:%M:%S%Z");

console.log(parser("2017-02-18T09:00:00+06:00"));
<script src="https://d3js.org/d3.v4.js"></script>
like image 33
altocumulus Avatar answered May 10 '26 20:05

altocumulus



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!