Set default timezone of browser window in javascript

We show graphs on our web page, which is based on GWT. The client system uses a different time zone from the server, and because of this, all schedules were not displayed correctly. Is there a way to set the default time zone when loading a page? Like we do this in java:

TimeZone.setDefault (TimeZone.getTimeZone ("Asia / Calcutta"));

Thanks!!!

+4
source share
2 answers

No, you cannot set the time zone of Date objects in javascript. Usually you only use UTC and epoch timestamps.

Only when creating a date from a string or from a year, month, etc. the local time zone will be used, you can get the time zone offset .

Converting the time zone can only be done by reconfiguring the Clock of the Day object (the example described here ), creating a date that looks similar, having a time offset interval, but just utc.

+4
source

If you use moment.js for your dates, you can set the default time zone for all newly created moments with:

 moment.tz.setDefault(String) 

https://momentjs.com/timezone/docs/#/using-timezones/default-timezone/

0
source

All Articles