0

I would like to get a user's timezone based on the device they are using. I'm aware that doing like, doing the following retrieves me the user's date based on the device they are using:

const dateToday = new Date()
dateToday.setFullYear(dateToday.getFullYear())

I attempted:

const timezone = jstz.determine()
const userTimezone = timezone.name()

But I would like to get back the timezone name in PDT, EST, etc. rather than America/New_York.

And var offset = dateToday.getTimezoneOffset() only gets me the offset.

So I was wondering in Javascript how to get a user's timezone's name based on the device user?

Thank you

My question is not duplicate

I did give the referred question a try but it only returns the offset in time. What I am looking for is timezone name in PDT, EST, etc. based on the user's device time.

Walter
  • 871
  • 3
  • 12
  • 16
  • Possible duplicate of [Getting the client's timezone in JavaScript](http://stackoverflow.com/questions/1091372/getting-the-clients-timezone-in-javascript) – Nicole Phillips Nov 07 '16 at 18:55
  • Why not make an array containing shortforms for each offset? – Jonas Wilms Nov 07 '16 at 18:56
  • @NicolePhillips Already checked it out and that's how I attempted `.getTimezoneOffset()`, but only gets me the offset time and not timezone name. – Walter Nov 07 '16 at 19:05
  • @Jonasw Sorry but could you show an example for clarification? So I can accept the answer as well. – Walter Nov 07 '16 at 19:05

1 Answers1

-1
var convert=["ABC","DEF"];
alert(convert[offset]);

This is maybe not the best answer, but its an easy way to convert the offset to your timezones string

Jonas Wilms
  • 132,000
  • 20
  • 149
  • 151