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.
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)
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/ )
The above is the detailed content of Python: it is now() time to migrate from utcnow(). For more information, please follow other related articles on the PHP Chinese website!