简体   繁体   English

D3.js时间格式

[英]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. 我在Z上添加了前导%, 似乎有效。 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. 在此之前,我将检查您使用的是哪个版本的d3。

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: 请注意(至少在我的Chrome版本上),该方法也适用:

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. 但是我不知道它在所有浏览器中都适用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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