时间在HighChart中无法正确显示

时间:2015-04-21 20:42:56

标签: c# json asp.net-mvc datetime highcharts

我正在使用HighStock Charts。

在数据库中我有UTC DateTime'2015-04-21 11:09:21.000':

enter image description here

我在我的代码中将其转换为自定义时区(在这种情况下应该+ 5小时):

TimeZoneInfo.ConvertTimeFromUtc(reading.dtUTCDateTime, assetCountryTimeZone);

enter image description here

如下所示,视图中的时间是正确的:即。

11:09 + 5 Hrs = 16:09

enter image description here

然后我在Json中转换数组/列表:

     <script type="text/javascript">
    var avgCustomArray2 = @Html.Raw(Json.Encode(avgCustomArray2));

// Display first
        var re = /-?\d+/;
 for (var i = 0; i < avgCustomArray2.length; i++) {
                    var m = re.exec(avgCustomArray2[i].date);

                    if (i == 0) {
                        console.log(new Date(parseInt(m[0])));
                        console.log(parseInt(m[0]));
                    }

// Removed Code from here:

}

    </script>

Console.log()

我得到了正确的日期时间:Tue Apr 21 2015 16:09:21 GMT+0100 (GMT Daylight Time)

以毫秒为单位:1429628961000静止(16:09)http://jsfiddle.net/3wux78tL/

因此,当我绘制图表时,我得到错误的时间(15:09):比正确值小1小时

enter image description here

这是HighChart Code设置:

 $("#container").highcharts("StockChart", {
                    chart: { zoomType: "x" },
                    rangeSelector: { enabled: false },
                    legend: { enabled: true },
                    yAxis: [
                        {
                            tickInterval: 0.5,
                            min: 0
                        }
                    ],
                    xAxis: [
                        {
                            title: { text: "Time " },
                            type: 'datetime'
                        }
                    ],
                    series: [
                        {
                            data: chartData,
                            tooltip: { valueDecimals: 2 }
                        }
                    ]
                });

enter image description here

1 个答案:

答案 0 :(得分:1)

请参阅:Highcharts - time off by 1 hour

尝试:

Highcharts.setOptions({
    global: {
        // timezoneOffset: +1,
        useUTC: false
    }
});