highcharts datetime axis,如何计算正确的时间戳?(highcharts datetime axis, how to comput correct timestamp?)

编程入门 行业动态 更新时间:2024-10-24 08:19:58
highcharts datetime axis,如何计算正确的时间戳?(highcharts datetime axis, how to comput correct timestamp?)

假设我想绘制一个系列,其中第一个点代表2013年11月5日11:30的时间。如果我在不同的时区使用浏览器查看我的图表,我希望时间11:30相同。 因此我想useUTC = true。 现在,我如何计算赋予highcharts的值(毫秒)?

我试过这个python代码:

>>> import datetime,time >>> t=datetime.datetime(2013,11,5,11,30,00) >>> time.mktime(t.timetuple())*1000 1383647400000.0

但是如果我在高位图中插入值1383647400000.0,我会得到一个时间点10:30而不是11:30。

这是一个重现故障的代码: http : //jsfiddle.net/2BffA/6/

我究竟做错了什么?

Let say I want to draw a series where the first point represents the time 11:30 of november 5 2013. I want the time 11:30 to be the same if I look my chart with a browser in a different timezone. Hence I want useUTC=true. Now, how do I compute the value (milliseconds) to give to highcharts?

I tried with this python code:

>>> import datetime,time >>> t=datetime.datetime(2013,11,5,11,30,00) >>> time.mktime(t.timetuple())*1000 1383647400000.0

But if I plug the value 1383647400000.0 in highcharts I obtain a point with time 10:30 instead of 11:30.

Here is a the code reproducing the malfunctioning: http://jsfiddle.net/2BffA/6/

What am I doing wrong?

最满意答案

问题出在python代码中...构建UTC时间戳的正确方法是2013年11月5日11:30

>>> import datetime, calendar >>> t=datetime.datetime(2013,11,5,11,30,00) >>> calendar.timegm(t.utctimetuple())*1000.0 + t.microsecond * 0.0011383651000000.0 1383651000000.0

如果useUTC = true,这是发送到highcharts的正确时间戳

The problem was in the python code... The correct way to construct a UTC timestamp for 11:30 november 5, 2013 is

>>> import datetime, calendar >>> t=datetime.datetime(2013,11,5,11,30,00) >>> calendar.timegm(t.utctimetuple())*1000.0 + t.microsecond * 0.0011383651000000.0 1383651000000.0

which is the correct timestamp to send to highcharts if useUTC=true

更多推荐

本文发布于:2023-07-16 22:54:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1135407.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:正确   时间   axis   highcharts   datetime

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!