admin管理员组

文章数量:1302985

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 ?

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 ?

Share Improve this question asked Sep 13, 2012 at 1:14 RaghuveerRaghuveer 1,4933 gold badges24 silver badges41 bronze badges 1
  • Here is the jsfidle link: jsfiddle/SLB4P/1 – Raghuveer Commented Sep 13, 2012 at 17:50
Add a ment  | 

2 Answers 2

Reset to default 9

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

Conversion problems are an extremely mon occurrence whenever dealing with date and time.

This link here shows the solution, to multiply by 1000, to get correct version.

Hope that helps.

本文标签: javascriptHighstocks epoch time mismatch with time zoneStack Overflow