converting from local to utc timezone

后端 未结 3 638
天命终不由人
天命终不由人 2021-02-10 19:38

I\'m attempting to craft a function that takes a time object and converts it to UTC time. The code below appears to be off by one hour. When i run noon through the converter,

3条回答
  •  离开以前
    2021-02-10 20:27

    Change

    src_dt = dt.replace(tzinfo=src_tz)
    

    to

    src_dt = src_tz.localize(dt)
    

    Using localize adjusts for Daylight Savings Time, while replace does not. See the section entitled "Localized times and date arithmetic" in the docs.

提交回复
热议问题