highcharts datetime轴,如何计算正确的时间戳? [英] highcharts datetime axis, how to comput correct timestamp?

查看:796
本文介绍了highcharts datetime轴,如何计算正确的时间戳?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

让我们想画一个系列,其中第一个点代表2013年11月5日11:30的时间。如果我用不同时区的浏览器查看我的图表,我希望11:30的时间是一样的。所以我想要useUTC = true。现在,我如何计算给予highcharts的值(毫秒)?



我尝试使用这个python代码:

 >>>导入日期时间,时间
>>>> t = datetime.datetime(2013,11,5,11,30,00)
>>>> time.mktime(t.timetuple())* 1000
1383647400000.0

但是如果我插在highcharts中的价值1383647400000.0我得到一个点与时间10:30而不是11:30。



以下是重现故障的代码: http: //jsfiddle.net/2BffA/6/



我做错了什么?

解决方案

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

 >>>导入日期时间,日历
>>> t = datetime.datetime(2013,11,5,11,30,00)
>>>> calendar.timegm(t.utctupuple())* 1000.0 + t.microsecond * 0.0011383651000000.0
1383651000000.0

如果useUTC = true,那么发送到highcharts的正确时间戳记


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?

解决方案

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

这篇关于highcharts datetime轴,如何计算正确的时间戳?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆