0

I cannot find any function to get the timezone as string in typescript, like 'Europe/Berlin'

The Date class can just show me the timezoneOffset

Makuna
  • 558
  • 1
  • 6
  • 19
  • No, like I said, I know, that there is a funtion to get the offset. But I need to timezone name as a string. – Makuna Aug 16 '22 at 06:30
  • 2
    The linked duplicate has answers to both. See [this answer](https://stackoverflow.com/a/34602679/14637). – Thomas Aug 16 '22 at 06:42

1 Answers1

0

Moment js and moment-timezone are in maintenance mode. it support most of Browser. It's not dead so you can still use it.

However it has some limitation like Tree shaking - reduce build size by import function as per need.

  1. Luxon js - enhanced version of moment.js which have tree shaking and other advantages.

    DateTime.local().zoneName;
    
    Output: America/Chicago
    
  2. You can still use moment-timezone as mention here. https://momentjs.com/timezone/

    Below method will give you clients timezone in the format you needs.

    moment.tz.guess();
    
    Output: America/Chicago
    

Here is an other alternative way similar to moment js.

https://momentjs.com/docs/#/-project-status/recommendations/

Dipten
  • 1,031
  • 8
  • 16