javascript Highcharts 将 x 轴时间转换为本地时间
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16004926/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Highcharts convert x-axis time to localtime
提问by David542
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.
我有一个图表,需要根据用户的本地时间显示服务器正常运行时间。UTC 是不可接受的,因为它需要显示用户的计算机时间。
Is there a way to convert the x-axis time to localtime? My current input looks something like this:
有没有办法将 x 轴时间转换为本地时间?我当前的输入看起来像这样:
[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)?
如果在 highcharts 中不可能,我如何将上面的 UTC 转换为用户的本地时间(即偏移 UNIX_TIMESTAMP)?
回答by jlbriggs
You can set useUTC to false in your global options:
您可以在全局选项中将 useUTC 设置为 false:
回答by Reality Extractor
Here's how to get the local timezone offset from UTC in minutes in Javascript
以下是如何在 Javascript 中以分钟为单位从 UTC 获取本地时区偏移量
var d = new Date();
var tzOffset = d.getTimezoneOffset();
Once you have that you simply subtract that from your UNIX_TIMESTAMP and that's that.
一旦你有了它,你只需从你的 UNIX_TIMESTAMP 中减去它,就是这样。
Also, you may want to consider to not pass time values for every data point to Highcharts but instead use the pointStart and pointIntervalseries properties and then just pass the data.
此外,您可能需要考虑不将每个数据点的时间值传递给 Highcharts,而是使用pointStart 和 pointInterval系列属性,然后只传递数据。