最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - D3.js utcParse() returns null - Stack Overflow

programmeradmin0浏览0评论

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

3 Answers 3

Reset to default 6

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

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.

发布评论

评论列表(0)

  1. 暂无评论