gpt4 book ai didi

返回 1969 年 12 月 31 日的 Javascript Date 对象

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

enter image description here如果您使用毫秒形式的日期,是否需要将其转换为字符串以便 Date 对象识别它?

"values":[ {x:1390636800000 , y:12} , 
{ x:1390640400000 , y:17} ,
{ x:1390644000000 , y:17},
{ x:1390647600000 , y:15},
{ x:1390651200000 , y:8} ]

如果是这样,我将如何转换它以便它被正确使用

chart.xAxis
.axisLabel("Time (s)")
.tickFormat(function(d){return d3.time.format('%I%p')(new Date(d))});

它没有吐出 December/31/1969 日期?我试图对整个对象进行字符串化,但这没有用。有什么建议么?感谢您的帮助,如果这是一个愚蠢的问题,我们深表歉意

(编辑)这是我正在使用的工作代码,它不能正确显示时间

var chart;

nv.addGraph(function() {
chart = nv.models.lineChart()
.options({
margin: {left: 100, bottom: 100},
x: function(d,i) { return i},
showXAxis: true,
showYAxis: true,
transitionDuration: 250
})
;

chart.xAxis
.axisLabel("Time (s)")
.tickFormat(function(d){return d3.time.format('%m/%d/%y')(new Date(d))});

chart.yAxis
.tickFormat(d3.format('d'))
;

d3.select('#chart1 svg')
.datum(data1())
.call(chart);

nv.utils.windowResize(chart.update);


chart.dispatch.on('stateChange', function(e) { nv.log('New State:', JSON.stringify(e)); });

return chart;
});

function data1() {

return [
{
"values":[ {x:1390636800000 , y:12} , { x:1390640400000 , y:17} , { x:1390644000000 , y:17}, { x:1390647600000 , y:15}, { x:1390651200000 , y:8} ],
"key": "First Dude "
},
{
"values": [ { x:1390636800000 , y:16} , { x:1390640400000 , y:16} , { x:1390644000000 , y:16}, { x:1390647600000 , y:12}, { x:1390651200000 , y:5}],
"key": "Second Dude "
},
{
"values": [ { x:1390636800000 , y:5} , { x:1390640400000 , y:5} , { x:1390644000000 , y:5}, { x:1390647600000 , y:3}, { x:1390651200000 , y:1}],
"key": "Third Dude "
}
,
{
"values": [ { x:1390636800000 , y:8} , { x:1390640400000 , y:18} , { x:1390644000000 , y:18}, { x:1390647600000 , y:9}, { x:1390651200000 , y:7}],
"key": "Fourth Dude "
}
];

}

最佳答案

If you are using a date in the form of milliseconds does it need to be converted to a string in order for the Date object to recognize it?

不可以,该值必须是数字(例如 1390636800000 而不是“1390636800000”)。如果提供了字符串,Date 将尝试解析它。

其中 time value提供给 Date 构造函数,假定为自 1970-01-01T00:00:00Z 以来的毫秒数。即 UTC。

因此,如果您处于 UTC -5:00 时区,则

new Date(0);

将返回一个本地日期和时间为 1969-12-31T19:00:00UTC-05:00 的对象

关于返回 1969 年 12 月 31 日的 Javascript Date 对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21226438/

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