converting from local to utc timezone

后端 未结 3 576
天命终不由人
天命终不由人 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:23

    By using the replace method on the datetime, you're not allowing the time zone to be adjusted for daylight savings time. Try using one of the documented methods from the pytz documentation:

    src_dt = src_tz.localize(dt)
    

提交回复
热议问题