Python datetime.utcnow() returning incorrect datetime

前端 未结 4 1864
渐次进展
渐次进展 2020-11-29 08:33
datetime.utcnow()

This call is returning an incorrect datetime, delayed from UTC/GMT by 1 hour (check in: http://www.worldtimeserver.com/current_ti

4条回答
  •  旧时难觅i
    2020-11-29 09:04

    I know I'm five years late, but I had the same problem tonight. In my experience, the solution to the problem was to use the aware UTC datetime:

    utc_dt_aware = datetime.datetime.now(datetime.timezone.utc)
    

    If you google "utcnow() wrong" this is the first result you get, so I thought it would be good to answer anyway.

提交回复
热议问题