简体   繁体   中英

D3.js time format

我需要在d3中解析日期时间字符串和语言环境信息2014-03-12T15:47:17.000+0000的帮助,我尝试了以下var iso = d3.time.format.utc("%Y-%m-%dT%H:%M:%S.%LZ+0000")但无效。

I added a leading % on the Z which seems to have worked. This is different to the example in the documentation, so if you're convinced that the documentation isn't correct then open an issue. Before doing that I'd check which version of d3 you're using.

Back to the question at hand, I set the formatter like this:

formater = d3.time.format("%Y-%m-%dT%H:%M:%S.%L%Z")

and tested it by passing your string to the formatter like this:

formater.parse("string")

Which resulted in:

Thu Mar 13 2014 02:47:17 GMT+1100 (AUS Eastern Summer Time)

d3.time.format.utc("%Y-%m-%dT%H:%M:%S.%L%Z")
  .parse('2014-03-12T15:47:17.000+0000')

// Wed Mar 12 2014 11:47:17 GMT-0400 (EDT)

Note that (at least on my version of Chrome) this works too:

new Date('2014-03-12T15:47:17.900+0000')

// Wed Mar 12 2014 11:47:17 GMT-0400 (EDT)

But I don't know that it works in all browsers.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM