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!
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!
Share Improve this question asked Feb 20, 2017 at 8:42 hanserinohanserino 13011 bronze badges3 Answers
Reset to default 6Instead 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
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/d3.v4.js"></script>
That looks like an ISO 8601 datetime string. Why not try isoParse
instead of utcParse
?
d3.isoParse('2017-02-18T09:00:00+06:00')
For me this returns:
2017-02-18T03:00:00.000Z
Which is a correctly timezone-adjusted UTC datetime.