Home Forums Chart Support dateTime stamp time zone Reply To: dateTime stamp time zone



JavaScript’s Date object tracks time in UTC internally, but typically accepts input and produces output in the local time of the system it’s running on. As you are looking to display time in a particular timezone, you can use the toLocaleString() method to convert a Date object to a string, using locale settings. You can output dates that are in UTC or local time to a specific timezone by passing timeZone option to toLocaleString() and its variations. For example:

var dateTime = new Date("2021-03-09T00:00:00.000+08:00");
dateTime.toLocaleString('en-US', { timeZone: 'America/New_York' })
//=> "3/8/2021, 11:00:00 AM"
// (midnight in China on March 9th is 11:00 AM in New York on March 8th)

You can also refer to this Stack Overflow thread for more information on initializing JavaScript date object to a particular timezone.

Shashi Ranjan
Team CanvasJS