gpt4 book ai didi

javascript - d3 时间格式返回 null

转载 作者:行者123 更新时间:2023-11-30 16:23:05 25 4
gpt4 key购买 nike

我有下面的代码,我正在尝试与 d3.time.format() 形成我在 time 变量中作为示例传递的日期是12 月 24 日星期四 04:59:54。根据文档,d3 时间格式化程序是严格的,如果 format() 参数与传入要解析的时间不匹配,将返回 null,但作为据我所知,我传递的格式正确,但仍然为空。

time = "Thu Dec 24 04:59:54";
parseTime = d3.time.format("%a%b%e%H:%M:%S");
console.log("PARSE TIME" + parseTime.parse(time));

编辑:这是我正在使用的文档 https://github.com/mbostock/d3/wiki/Time-Formatting#format

最佳答案

这是因为您的 .format 没有考虑空格,因此您需要将其更改为:

parseTime = d3.time.format("%a %b %e %H:%M:%S"); 

使用您的示例。或者您可以在应用 .parse 之前从 time 变量中删除空格。

关于javascript - d3 时间格式返回 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34468828/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com