3

I have gone through lot of threads on this and looks like we can't change the browser's timezone programmatically. We have moment-timezone.js library using which we can set timezone but that is applicable only to its objects. If you are still using javascript native new Date(), then you will still get date in browsers timezone.

I am having angularjs application where I am using kendo Ui Widgets and momentjs library for dates.

I will have to take care of both Kendo and momentjs independently everywhere in the code. So question again here is, Is there really NO way we can set the browsers timezone programmatically like we do for Java applications using JVM user.timezone VM argument ?

Thanks Matt, but I can't control which browser user will use. Can I override javascript date constructor, do you see any issue in that approach ?

    var origConst = Date.prototype.constructor;
Date = function(Date) {
    var d = new origConst();
    var timeZoneDiff = -5; //time zone value of user
    //get the timezone offset from local time in minutes
    var tzDifference = timeZoneDiff * 60 + d.getTimezoneOffset();
    var newD = new origConst(d.getTime() + (tzDifference * 60 * 1000));
    return newD;
};
Sohan Soni
  • 1,207
  • 21
  • 35
  • Correct - There really is no way to set the browser's default time zone programmatically. – Matt Johnson-Pint Aug 11 '16 at 00:04
  • You might look at [this answer](http://stackoverflow.com/questions/26099858/change-timezone-of-browser) also, thought I don't think that applies exactly for the scenario you describe. – Matt Johnson-Pint Aug 11 '16 at 00:06

1 Answers1

1

The time zone offset of JavaScript Date objects depends entirely on the operating system's regional settings. It cannot be changed via JavaScript code.

dimodi
  • 3,969
  • 1
  • 13
  • 23