javascript d3 timeParse utcParse
javascript d3 timeParse utcParse
有人可以提供有关如何解析像这样通过的数据的提示吗?
2020-07-02 15:27:05.000000,73.78999328613281
2020-07-02 15:42:10.000000,73.9699935913086
2020-07-02 15:57:16.000000,73.70999145507812
2020-07-02 16:12:21.000000,73.90999603271484
2020-07-02 16:27:26.000000,74.27999114990234
2020-07-02 16:42:32.000000,74.07999420166016
2020-07-02 16:57:37.000000,73.99999237060547
2020-07-02 17:12:42.000000,74.2699966430664
2020-07-02 17:27:47.000000,74.28999328613281
2020-07-02 17:42:52.000000,74.14999389648438
2020-07-02 17:57:56.000000,73.9699935913086
我正在尝试使用 timeParse
和 utcParse
以及 d3 库。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<!-- Load d3.js -->
<script src="https://d3js.org/d3.v4.js"></script>
<!-- Create a div where the graph will take place -->
<div id="my_dataviz"></div>
</head>
<script>
time = d3.timeParse("%m/%d/%Y %H:%M:%S %p")("1/2/2014 8:22:05 AM");
console.log(time);
time2 = d3.utcParse("%Y-%m-%dT %H:%M:%S")("2020-07-02 17:57:56.000000");
console.log(time2);
</script>
</body>
</html>
I am trying to follow the d3 documentation,但是当通过开发控制台查看 html 文件时,这将为 utcParse attempt
产生空值。有人有什么建议吗?
Date Thu Jan 02 2014 08:22:05 GMT-0600 (Central Standard Time)
test.html:17:11
null
使用 the d3 format docs 作为参考,您需要构建一个与您的数据完全匹配的说明符(否则您将在 100% 的情况下得到“null”)。
您会在文档中注意到 %S
指的是 2 位十进制秒数 - 哦哦,数据中有秒,然后是六位小数(微秒)。
因此,我们希望 %S
后跟小数点,而不是 %S
,然后是 %f
指令,即 6 位微秒。
日期和时间部分之间的“T”只是日期格式的一部分,UTC 和 ISO-8601(以及其他可能)在该位置使用 T。代码段的输出以 UTC 格式显示带有 T.
的日期
time2 = d3.utcParse("%Y-%m-%d %H:%M:%S.%f")("2020-07-02 17:57:56.000000");
console.log(time2);
<script src="https://d3js.org/d3.v4.js"></script>
有人可以提供有关如何解析像这样通过的数据的提示吗?
2020-07-02 15:27:05.000000,73.78999328613281
2020-07-02 15:42:10.000000,73.9699935913086
2020-07-02 15:57:16.000000,73.70999145507812
2020-07-02 16:12:21.000000,73.90999603271484
2020-07-02 16:27:26.000000,74.27999114990234
2020-07-02 16:42:32.000000,74.07999420166016
2020-07-02 16:57:37.000000,73.99999237060547
2020-07-02 17:12:42.000000,74.2699966430664
2020-07-02 17:27:47.000000,74.28999328613281
2020-07-02 17:42:52.000000,74.14999389648438
2020-07-02 17:57:56.000000,73.9699935913086
我正在尝试使用 timeParse
和 utcParse
以及 d3 库。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<!-- Load d3.js -->
<script src="https://d3js.org/d3.v4.js"></script>
<!-- Create a div where the graph will take place -->
<div id="my_dataviz"></div>
</head>
<script>
time = d3.timeParse("%m/%d/%Y %H:%M:%S %p")("1/2/2014 8:22:05 AM");
console.log(time);
time2 = d3.utcParse("%Y-%m-%dT %H:%M:%S")("2020-07-02 17:57:56.000000");
console.log(time2);
</script>
</body>
</html>
I am trying to follow the d3 documentation,但是当通过开发控制台查看 html 文件时,这将为 utcParse attempt
产生空值。有人有什么建议吗?
Date Thu Jan 02 2014 08:22:05 GMT-0600 (Central Standard Time)
test.html:17:11
null
使用 the d3 format docs 作为参考,您需要构建一个与您的数据完全匹配的说明符(否则您将在 100% 的情况下得到“null”)。
您会在文档中注意到 %S
指的是 2 位十进制秒数 - 哦哦,数据中有秒,然后是六位小数(微秒)。
因此,我们希望 %S
后跟小数点,而不是 %S
,然后是 %f
指令,即 6 位微秒。
日期和时间部分之间的“T”只是日期格式的一部分,UTC 和 ISO-8601(以及其他可能)在该位置使用 T。代码段的输出以 UTC 格式显示带有 T.
的日期time2 = d3.utcParse("%Y-%m-%d %H:%M:%S.%f")("2020-07-02 17:57:56.000000");
console.log(time2);
<script src="https://d3js.org/d3.v4.js"></script>