Set default TimeZone of the browser window in javascript

18,262

Solution 1

No, you can't set the timezone of Date objects in javascript. Usually you use only UTC and epoch-based timestamps.

Only when creating a Date from a string or from year, month etc. the local timezone will be used, you can only get the timezone offset.

Converting a timezone can only be done by re-setting the Hours of the Date object (example described here), creating a date which looks-like having an offset timezone but is just utc.

Solution 2

In case you are using moment.js for your dates, you can set the default timezone for all newly created moments with:

moment.tz.setDefault(String)

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

Share:
18,262
Arun
Author by

Arun

Updated on June 09, 2022

Comments

  • Arun
    Arun almost 2 years

    We are displaying schedules on our webpage which is build on GWT. Client system using different timezone from server and because of that, all the schedules were displaying wrong. Is there a way to set default time zone when we load the page? Like the way we do it in java:

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

    Thanks!!!