Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Highstocks epoch time mismatch with time zone

I am trying to populate a graph using highstocks library. I am giving epoch time as input for x axis. I am able to generate the graph successfully but the problem is that the epoch time converted by highstock is mismatching with my time zone. For example

My input epoch time is : 1347497100000

Present result after convertion is: Thu, 13 Sep 2012 00:45:00 GMT

Expected result is : Wed Sep 12 2012 17:45:00 GMT-0700

This time zone mis match is the wrong value which is being displayed right now.

I tried setting this property also, but no luck:

global: {
    useUTC: false
},

I am in pacific time zone. When I tried doing :

console.log(new Date)

from the same script, it returns me the time in pacific time.

Can you please advice how to fix the mismatch of this time zone ?

like image 707
Raghuveer Avatar asked Sep 13 '12 01:09

Raghuveer


1 Answers

It may be a good idea to read the global.useUTC api reference again

Global options that don't apply to each chart. These options, like the lang options, must be set using the Highcharts.setOptions method.

Highcharts.setOptions({
    global: {
        useUTC: false
    }
});

What that means is the global property is not really applicable to any chart in particular and Highcharts would blindly ignore the option even if you set it in an individual chart like

var chart=new Highcharts.StockChart({
{
  ...
    global: {
        useUTC: false
    }
  ...
});

In short set the global option explicitly using the Highcharts.setOptions method before you create any chart object
Local/Client Time Zone | Highchart & Highstock @ jsFiddle

like image 197
Jugal Thakkar Avatar answered Nov 07 '22 12:11

Jugal Thakkar