Python datetime.utcnow() returning incorrect datetime

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.

Leave a Comment