1

I am use moment library for getting time zone

moment.tz.guess()

which is returning 'Asia/Calcutta' (old name), instead of that I want the latest name which is 'Asia/Kolkata' (new name).

Or any other way to get this new name time zone.

isherwood
  • 58,414
  • 16
  • 114
  • 157
jenish lila
  • 131
  • 7
  • 2
    You could make the replacement yourself on your end. It looks like this has been reported before: https://github.com/moment/moment-timezone/issues/934, https://github.com/moment/moment-timezone/issues/916 – Felix Kling Oct 08 '21 at 14:05
  • [From one of the issues](https://github.com/moment/moment-timezone/issues/916#issuecomment-739320350): *"It needs to return new name, "Asia/Kolkata" but I believe it is not a moment issue. It is a browser specific issue. moment.tz.guess() gives "Asia/Calcutta" on Chrome, but "Asia/Kolkata" on Firefox https://bugs.chromium.org/p/chromium/issues/detail?id=580195"* – Felix Kling Oct 08 '21 at 14:07
  • @FelixKling Could it be my chrome version problem? – jenish lila Oct 08 '21 at 14:09
  • @FelixKling also I tried to use this also 'moment.tz.guess(true)' but it is not working, and libraries I am using is moment.js and moment-timezone.js – jenish lila Oct 08 '21 at 14:13
  • Looks like it's still an unresolved bug in Chrome. – Felix Kling Oct 08 '21 at 14:15

1 Answers1

1

As Felix suggested, just make the replacement on your end:

let timezoneGuess = moment.tz.guess();
timezoneGuess = timezoneGuess.replace("Calcutta","Kolkata");

This code tries to find "Calcutta" in the timezone name and, if it's there, replaces it with "Kolkata."

  • what will happen if I am on another time zone 'America/Los_angeles' , will this return error? – jenish lila Oct 08 '21 at 14:25
  • 1
    @jenishlila: No. If `replace` doesn't find the string, it returns the value as is. You can try it for yourself: `'America/Los_angeles'.replace("Calcutta","Kolkata")`. – Felix Kling Oct 08 '21 at 23:06