0

I was working with some timezone code when I noticed this ambiguity. When trying to get the tzname for Asia/Singapore, I get the UTC Offset. If I do the same with Asia/Kolkata, I get the correct timezone name - IST.

pytz.timezone('Asia/Singapore').tzname(datetime.now())
'+08'
pytz.timezone('Asia/Kolkata').tzname(datetime.now())
'IST'

Is there a reason for this ambiguity and is there a workaround that will give me the actual timezone code i.e. SGT?

Nikit Parakh
  • 65
  • 1
  • 7
  • Does this answer your question? [How to use abbreviated timezone name(PST, IST) in Pytz](https://stackoverflow.com/questions/37109945/how-to-use-abbreviated-timezone-namepst-ist-in-pytz) – esqew Jul 08 '21 at 18:16

1 Answers1

0

I don't think pytz have 'SGT' in the timezone abbreviation list. I have the following code:

from datetime import datetime as dt
common_name = pytz.timezone('Asia/Singapore')
abbr = common_name.localize(dt.now(), is_dst=None)
print(abbr.tzname())

And it give me the output +08. Bu for other zones like:

from datetime import datetime as dt
common_name = pytz.timezone("US/Pacific")
abbr = common_name.localize(dt.now(), is_dst=None)
print(abbr.tzname())

it gives me PDT. And I tried several other timezones and seems like they don't include SGT in their list. Maybe they will have it in future versions, but right now they just don't have it.

Zichzheng
  • 1,090
  • 7
  • 25