Warm tip: This article is reproduced from stackoverflow.com, please click
highcharts

Format highcharts date tooltip to display timezone

发布于 2020-03-27 10:19:58

I want to display the time zone on the date/time tooltip.

The xDateFormat option does not have an option to display timezone.

https://jsfiddle.net/u7z28fbp/1/

For eg:

Currently the date tooltip shows: Friday, April 5, 2019

I want it to show: Friday, April 5, 2019 UTC +00:00

Questioner
Hamed
Viewed
55
user3738936 2019-07-04 00:21

Try this:

https://jsfiddle.net/q8s2jdgp/1/

Highcharts.chart('container', {

xAxis: {
    type: 'datetime'
},

tooltip: {
    xDateFormat: '%A, %B %d, %Y UTC ' + dayjs().format("Z") ,
    shared: true
},

plotOptions: {
    series: {
        pointStart: Date.UTC(2012, 0, 1),
        pointInterval: 24 * 3600 * 1000
    }
},

series: [{
    data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4]
}, {
    data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4].reverse()
}]
});

If you want to change what the UTC value is to the right you will want to write some code around that to create a variable and use concatenation or interpolation.

I used day.js, here are other ways you can get the timestamp from the browser. get client time zone from browser

There are a few resources around to do datetime formatting, I used this one: https://thoughtbot.com/blog/how-to-find-a-time-format-for-rubys-strftime