Reputation: 110163
I have a graph that needs to show server up-time against the user's local time. UTC is not acceptable, as it needs to show the user's computer time.
Is there a way to convert the x-axis time to localtime? My current input looks something like this:
[UNIX_TIMESTAMP,1], [UNIX_TIMESTAMP, 2], ...
If not possible in highcharts, how would I convert the above in UTC to in the user's localtime (i.e., offset the UNIX_TIMESTAMP)?
Upvotes: 12
Views: 20848
Reputation: 17791
You can set useUTC to false in your global options:
http://api.highcharts.com/highcharts#global.useUTC
Upvotes: 22
Reputation: 1277
Here's how to get the local timezone offset from UTC in minutes in Javascript
var d = new Date();
var tzOffset = d.getTimezoneOffset();
Once you have that you simply subtract that from your UNIX_TIMESTAMP and that's that.
Also, you may want to consider to not pass time values for every data point to Highcharts but instead use the pointStart and pointInterval series properties and then just pass the data.
Upvotes: 2