6

Google Chrome

new Date()
//returns Fri Mar 29 2013 17:55:25 GMT+0530 (IST)

IE8

new Date()
//returns Fri Mar 29 17:48:46 UTC+0530 2013

I need to extract (IST) part from the Date on IE,On chrome I could do dateString.substring to extract it but on IE I cannot do that.

The method getTimeZoneOffset gives me the offset in minutes, is there a way to get the string using the offset ?

Or do I need to research for all the timezone strings corresponding to the offsets and create an object out of it & then use it ?

Spudley
  • 166,037
  • 39
  • 233
  • 307
Mudassir Ali
  • 7,913
  • 4
  • 32
  • 60
  • What do you plan to do with the abbreviation or offset? If your goal is to map this back to a time zone, you are on the wrong track. Many time zones have the same offset, and many abbreviations can be used for more than one time zone. There is no 100% reliable way to detect the user's time zone automatically, but jsTimeZoneDetect is often good enough. You still want to allow your user to change their time zone if the detection wasn't accurate though. If you plan to do something else - then please elaborate. – Matt Johnson-Pint Mar 29 '13 at 18:45
  • The same thing, I'd want to display the abbreviation along with the timestamp to the user, and then I stumbled upon this issue of not being able to decide which abbreviation to choose when more than two locations with different abbreviations share same timezone – Mudassir Ali Mar 30 '13 at 05:49
  • It's a good question because a valid reason for wanting the parenthesized timezone is for vanity display purposes. Even if you parse it with a regex, and default to "local time" if it doesn't parse. Language implementation-wise, it is dumb that in 2015 they can't decide on a standardization. Secondly, it's ridiculous that it is displayed in the .toString() method but does not have its own getter method. But that is a criticism of the implementation (and every vendor, equally at that) and not the question. – lol Nov 16 '15 at 11:52

2 Answers2

4

Can this be of service to you?

jsTimezoneDetect

Also this might also be a relevant read: How can I determine a timezone by the UTC offset?

Community
  • 1
  • 1
OpherV
  • 6,787
  • 6
  • 36
  • 55
  • Thanks, this is pretty much the one, but again it doesn't solve the issue when two locations share same timezone(this issue wasnt included in the question though), I'll wait for other answers, if I dont find any, this'll be my choice, also this is cross browser compatible :) – Mudassir Ali Mar 30 '13 at 06:27
  • 1
    IS jsTimezoneDetect compatible with IE11? – Mark Jan 25 '18 at 15:49
1

I don't think that there's a way to do what you want reliably in the standard JS date object, but here are some libraries that may help you:

Maybe one of them will give you the info you're looking for.

hope that helps.

Spudley
  • 166,037
  • 39
  • 233
  • 307
  • Thanks for the links, I like the way detect_timezone.js deals with different locations dealing with similar timezones by concatenating them, but the string is pretty large to be displayed in my use case – Mudassir Ali Mar 30 '13 at 06:30