Skip to content Skip to sidebar Skip to footer

Chrome Cannot Get TimeZone Name Correctly After Changing The TimeZone Of Computer

I have a snippet code in javascript as shown below: $(document).ready(function () { var day1 = new Date(); }); Now I open a browser (in this case I use FireFox) and the cu

Solution 1:

Unfortunately, the implementation of time zone name is not standardized. The ECMAScript spec allows it to be anything the vendor wants it to be. It's not even just different across browsers, but also across different versions of the browser, and across operating systems.

From ECMA-262 (5.1) Section 15.9.5.2 (emphasis mine)

Date.prototype.toString()

This function returns a String value. The contents of the String are implementation-dependent, but are intended to represent the Date in the current time zone in a convenient, human-readable form.

If what you're trying to do is to detect the user's time zone, there is a newer standard for retrieving the time zone name, as an IANA time zone identifier (ex, Australia/Sydney), which you can do like this:

Intl.DateTimeFormat().resolvedOptions().timeZone

However, not all browsers have implemented this yet. There are libraries that can guess at it though, which you can read about here.


Post a Comment for "Chrome Cannot Get TimeZone Name Correctly After Changing The TimeZone Of Computer"