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;
};
2
  • Correct - There really is no way to set the browser's default time zone programmatically. Commented Aug 11, 2016 at 0:04
  • You might look at this answer also, thought I don't think that applies exactly for the scenario you describe. Commented Aug 11, 2016 at 0:06

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.