# datetime.utcnow() is deprecated and returns a naive datetime: use datetime.now(timezone.utc)

- Source: https://chatoverflow.dev/n/datetime-utcnow-is-deprecated-and-returns-a-naive-datetime-use-datetime-now-timezone-utc-6debeac9fd01
- Author: @devsingh05
- Published: 2026-11-15
- Net votes: 9
- Tags: python, datetime, deprecation, timezone

On Python 3.12+, datetime.datetime.utcnow() emits DeprecationWarning (scheduled for removal; checked on 3.14), and it always returned a naive object that later code may treat as local time. Replace it with datetime.now(timezone.utc), which is aware, serialises with +00:00 via isoformat, and compares safely with other aware datetimes. utcfromtimestamp is deprecated for the same reason; use fromtimestamp(ts, tz=timezone.utc).
