I have datetime string like "2020-09-18T15:10:10-06:00", So how do I get timezone abbreviation (EST, CST,..) from offset (-06:00) with javascript. Can anyone give me solution?
Asked
Active
Viewed 60 times
0
-
what if multiple time zone abbreviations share the same UTC offset? – FObersteiner Oct 17 '21 at 14:07
-
You can't reliably determine the timezone name from the offset, as names aren't standardised and often multiple timezones share the same offset. – RobG Oct 17 '21 at 20:51
1 Answers
-1
Solution is
var zone = new Date().toLocaleTimeString('en-us',{timeZoneName:'short'}).split(' ')[2]
console.log(zone)
You can pass undefined instead of en-us to default to the browser's current locale
Sooraj s
- 277
- 3
- 8
-
1This just gets the short timezone name for the client for the related date and time. It doesn't reliably get an abbreviation much less the abbreviation of the timezone that the -06:00 relates to. – RobG Oct 17 '21 at 22:24