Sparky
Sparky

Reputation: 91

How to use abbreviated timezone name(PST, IST) in Pytz

I need to know the way of using Abbreviated timezone name like PST, IST etc on pytz.

Now I can be able to convert between timezone using the timezone name like "America/Los_Angeles".

Instead I need to find the way of using timezone name like PST, IST etc.,

Sample code I have used now for conversion.

def local2utc(self, dt):

    from_zone = tz.gettz('America/Los_Angeles')
    to_zone = tz.gettz('UTC')
    local = dt.replace(tzinfo=from_zone)
    print("converted time")
    print(local.astimezone(to_zone).replace(tzinfo = None))
    return local.astimezone(to_zone).replace(tzinfo = None)

Someone let me know the way of achieving the same.

Upvotes: 1

Views: 2846

Answers (1)

acdr
acdr

Reputation: 4716

This is by nature impossible, because some abbreviations can mean multiple (different) time zones:

http://www.timeanddate.com/time/zones/

If you want it to work specifically for your timezones, make a dictionary mapping abbreviation to long name.

Upvotes: 1

Related Questions