Python: it is now() time to migrate from utcnow()
Andrea Grandi

Andrea Grandi @andreagrandi

About: My name is Andrea Grandi and I live in Italy. I work remotely as Python/Django developer for Supertab

Location:
Italy
Joined:
Apr 24, 2018

Python: it is now() time to migrate from utcnow()

Publish Date: Jul 17 '24
0 0

This morning I randomly found this post from Miguel Grinberg: It's Time For A Change: datetime.utcnow() Is Now Deprecated.

The main point is that Python utcnow() method is not timezone aware, and Python 3.12 is deprecating it. Therefore, you should start migrating your code to use now() instead.

Current state until Python 3.11

Until Python 3.11, the utcnow() method returns a datetime object, and you would use it like this:

>>> from datetime import datetime
>>> datetime.utcnow()
datetime.datetime(2024, 7, 17, 12, 17, 9, 835551)
Enter fullscreen mode Exit fullscreen mode

The issue with this method is that it doesn't include timezone information, so you can't be certain if the time is in UTC or not.

(the post continues on my blog https://www.andreagrandi.it/posts/python-now-time-to-migrate-from-utcnow/ )

Comments 0 total

    Add comment