Alright so I\'m using javascript to return the shorthand timezone of the users system time with a simple regex like so
new RegExp(\'\\\\(.*\\\\)\').exec(new
A few things:
Yes, the output of .toString()
on a JavaScript Date
object is implementation dependent. You will get different results on different operating systems, browsers, and versions. This is defined by ECMAScript 5.1 §15.9.5.2 as follows:
15.9.5.2 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.
Abbreviations like EST
and EDT
do not represent the entire time zone. They represent specifically the segment of the time zone that applies to that particular moment in time. remember, new Date()
is initialized to the current "now". See also "Time Zone != Offset" in the timezone tag wiki.
In general, time zone abbreviations are ambiguous. EST might mean Eastern Standard Time in the US, or it might mean Eastern Standard Time in Australia. Of course, they might use AEST in Australia, but who's to say that they are the ones to prepend an A instead of the Americans? Besides, EST could also mean Australian Eastern Summer Time. The abbreviation "CST" is even worse, having 5 different interpretations - two in Australia, one in the USA, one in China, and one in Cuba, and all have different offsets. See this list on Wikipedia for more examples.
The only standard for time zone abbreviations that are even defined in a specification are, those in RFC822 §5.1:
zone = "UT" / "GMT" ; Universal Time
; North American : UT
/ "EST" / "EDT" ; Eastern: - 5/ - 4
/ "CST" / "CDT" ; Central: - 6/ - 5
/ "MST" / "MDT" ; Mountain: - 7/ - 6
/ "PST" / "PDT" ; Pacific: - 8/ - 7
But this is a very discouraged format, as it's focused just on the USA and says very little about the rest of the world. The "military" zones A-Y were deprecated in RFC1123 anyway. Only "Z" to represent UTC remains in modern formats like ISO8601.
You've said what you want, but not why you want it. If you're just trying to determine the time zone of the user, please consider jsTimeZoneDetect which will return you an IANA time zone identifier, such as America/New_York
. You can then take that back to your server. Most platforms have either native support or libraries for working with these.
You can use Date#toISOString to get a consistent format.