unexpected results converting timezones in python

前端 未结 5 1978
谎友^
谎友^ 2020-11-27 17:27

I\'m trying to understand why I\'m getting these results when converting timezones to UTC:

In [74]: d1 = datetime(2007, 12, 5, 6, 30,tzinfo=pytz.timezone(\'U         


        
5条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-11-27 18:10

    I'm revisiting some questions about date and time to see if some of the newer libraries prove more helpful in situations like this (or not). pendulum is one that stores timezone with date and time, making it particularly valuable in situations such as this.

    >>> import pendulum
    >>> d1 = pendulum.datetime(2007,12,5,6,30, tzinfo='US/Pacific')
    >>> d1
    
    >>> d1.timezone
    
    >>> d1.astimezone(tz='UTC')
    
    

    Lots of other sweet features too.

提交回复
热议问题