1

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?

Emanuele Paolini
  • 9,912
  • 3
  • 38
  • 64
  • I'm sorry, but for me 1383647400000 is 10.30 in UTC, so it's displayed correctly? On a server side create UTC time. This may help: http://stackoverflow.com/questions/15940280/utc-time-in-python – Paweł Fus Nov 06 '13 at 16:43
  • So, the point is maybe in the python code.... Is time.mktime dependent on the localtime? – Emanuele Paolini Nov 06 '13 at 16:50
  • Yet, `time.mktime()` makes from local time, see another answer from [SO](http://stackoverflow.com/questions/2956886/python-calendar-timegm-vs-time-mktime). – Paweł Fus Nov 06 '13 at 16:53

1 Answers1

-1

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

Emanuele Paolini
  • 9,912
  • 3
  • 38
  • 64