1

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.

Sparky
  • 91
  • 1
  • 8
  • 1- do these abbreviations represent your local timezone? Otherwise the result may be ambiguous. See [Parsing date/time string with timezone abbreviated name in Python?](http://stackoverflow.com/q/1703546/4279) 2- your `local2utc()` is wrong. Do not use `.replace(tzinfo)` with a timezone that has a non-fixed utc offset such as `America/Los_Angeles`. See [Datetime Timezone conversion using pytz](http://stackoverflow.com/q/27531718/4279) – jfs May 10 '16 at 14:04

1 Answers1

1

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.

acdr
  • 4,538
  • 2
  • 19
  • 45