Search code examples
angulartimetimezoneutcmoment-timezone

Convert UTC time to desired timezone Angular


I know this question is asked several times but Im looking for more specifics. I would like to convert the UTC time to desired timezone and the timezones I get from the API are in the below format: (GMT-05:00) Eastern Time (US & Canada), (GMT) Greenwich Mean Time : London, (GMT+01:00) Amsterdam, Berlin, Bern, Rome, Stockholm, Vienna

And in some cases they are also abbreviated : CEST, PST etc

Im using moment-timezone but unable to figure out the right way of doing this. Looking for a solution

Cheers


Solution

  • From your comment:

    Its an internal API from my org which stores the timezones of employees

    I'm sorry, but there's no possible way we can help you. You'll need to sync with whomever is responsible for putting data into that system to understand where they got it from and how they intend for you to use it.

    In general, some of those strings look similar to Windows time zone display names, but once you're into abbreviations all bets are off (CST, IST, and many others have multiple meanings). There's no magic table that can map them back to something usable.

    The best practice for time zone fields in APIs is to use IANA time zone identifiers. For example, America/Los_Angeles, Europe/London, etc. See the full list here. If your organization's API is returning something else, then that should probably be changed - but you'll have to take that up with them.