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

£可爱£侵袭症+ 提交于 2019-12-11 11:06:59

问题


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.


回答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.



来源:https://stackoverflow.com/questions/37109945/how-to-use-abbreviated-timezone-namepst-ist-in-pytz

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!