Note that for Python 3.2 onwards, the datetime module contains datetime.timezone. The documentation for datetime.utcnow() says:

An aware current UTC datetime can be obtained by calling datetime.now(timezone.utc).

So, datetime.utcnow() doesn't set tzinfo to indicate that it is UTC, but datetime.now(datetime.timezone.utc) does return UTC time with tzinfo set.

So you can do:

>>> import datetime
>>> datetime.datetime.now(datetime.timezone.utc)
datetime.datetime(2014, 7, 10, 2, 43, 55, 230107, tzinfo=datetime.timezone.utc)

Since Python 3.11, there also exists datetime.UTC which is equivalent to datetime.timezone.utc. So you can also do datetime.datetime.now(datetime.UTC).

Answer from Craig McQueen on Stack Overflow
Top answer
1 of 10
388

Note that for Python 3.2 onwards, the datetime module contains datetime.timezone. The documentation for datetime.utcnow() says:

An aware current UTC datetime can be obtained by calling datetime.now(timezone.utc).

So, datetime.utcnow() doesn't set tzinfo to indicate that it is UTC, but datetime.now(datetime.timezone.utc) does return UTC time with tzinfo set.

So you can do:

>>> import datetime
>>> datetime.datetime.now(datetime.timezone.utc)
datetime.datetime(2014, 7, 10, 2, 43, 55, 230107, tzinfo=datetime.timezone.utc)

Since Python 3.11, there also exists datetime.UTC which is equivalent to datetime.timezone.utc. So you can also do datetime.datetime.now(datetime.UTC).

2 of 10
251

That means it is timezone naive, so you can't use it with datetime.astimezone

you can give it a timezone like this

import pytz  # 3rd party: $ pip install pytz

u = datetime.utcnow()
u = u.replace(tzinfo=pytz.utc) #NOTE: it works only with a fixed utc offset

now you can change timezones

print(u.astimezone(pytz.timezone("America/New_York")))

To get the current time in a given timezone, you could pass tzinfo to datetime.now() directly:

#!/usr/bin/env python
from datetime import datetime
import pytz # $ pip install pytz

print(datetime.now(pytz.timezone("America/New_York")))

It works for any timezone including those that observe daylight saving time (DST) i.e., it works for timezones that may have different utc offsets at different times (non-fixed utc offset). Don't use tz.localize(datetime.now()) -- it may fail during end-of-DST transition when the local time is ambiguous.

🌐
Python documentation
docs.python.org › 3 › library › datetime.html
datetime — Basic date and time types
As such, the recommended way to create an object representing the current time in UTC is by calling datetime.now(timezone.utc).
Discussions

Why is datetime.utcnow deprecated?
Just made an account to say that I agree with everyone in Deprecating `utcnow` and `utcfromtimestamp` saying that this is a bad idea. I feel it’s a case of one person forcing their own coding preferences on everybody else. I’ve not seen anything to convince me that the problems presented ... More on discuss.python.org
🌐 discuss.python.org
19
3
April 2, 2025
It's Time For A Change: datetime.utcnow() Is Now Deprecated
It’s deprecated starting DateTime.Now() More on reddit.com
🌐 r/programming
145
533
November 19, 2023
python - How can I get the current time (now) in UTC? - Stack Overflow
I have a python datetime object (representing five minutes from now) which I would like to convert to UTC. I am planning to output it in RFC 2822 format to put in an HTTP header, but I am not sure if More on stackoverflow.com
🌐 stackoverflow.com
Deprecating `utcnow` and `utcfromtimestamp` - Core Development - Discussions on Python.org
Previously, we have documented that utcnow and utcfromtimestamp should not be used, but we didn’t go so far as to actually deprecate them, and I wrote a whole article about how you shouldn’t use them. The main reason I … More on discuss.python.org
🌐 discuss.python.org
8
April 26, 2023
🌐
Miguel Grinberg
blog.miguelgrinberg.com › post › it-s-time-for-a-change-datetime-utcnow-is-now-deprecated
It's Time For A Change: datetime.utcnow() Is Now Deprecated - miguelgrinberg.com
The deprecation warning provides a hint of what they think we should use, and the deprecation notices included in the documentation are even more specific. Here is what the notice for the utcnow() function says: Deprecated since version 3.12: ...
🌐
GeeksforGeeks
geeksforgeeks.org › python › get-utc-timestamp-in-python
Get UTC timestamp in Python - GeeksforGeeks
July 12, 2025 - Python · from datetime import datetime # Get the current UTC time and convert to timestamp a = datetime.utcnow().timestamp() print(a) Output · 1743769015.000206 · Explanation: datetime.utcnow() returns the current UTC date and time.
🌐
Reddit
reddit.com › r/programming › it's time for a change: datetime.utcnow() is now deprecated
r/programming on Reddit: It's Time For A Change: datetime.utcnow() Is Now Deprecated
November 19, 2023 - If anything, now() should've been on the chopping block, not utcnow(). utcnow was returning a naive datetime, which is wrong for all practical calculations in Python.
🌐
Paul Ganssle
blog.ganssle.io › articles › 2019 › 11 › utcnow.html
Paul Ganssle - Stop using utcnow and utcfromtimestamp
October 9, 2022 - In Python 3, two things have changed that make utcnow unnecessary and, in fact, dangerous. The first is that a concrete time zone class, datetime.timezone, was introduced, along with a constant UTC object, datetime.timezone.utc. With this change, you now have a clear and unambiguous way to mark which of your datetimes are in UTC without bringing in third party code or implementing your own UTC class.
Find elsewhere
🌐
Python.org
discuss.python.org › core development
Deprecating `utcnow` and `utcfromtimestamp` - Core Development - Discussions on Python.org
April 26, 2023 - Previously, we have documented that utcnow and utcfromtimestamp should not be used, but we didn’t go so far as to actually deprecate them, and I wrote a whole article about how you shouldn’t use them. The main reason I had for not deprecating them at the time was that .utcnow() is faster than .now(datetime.UTC), and if you are immediately converting the datetime to a string, like datetime.utcnow().isoformat(), there’s no danger.
🌐
Duke
fintechpython.pages.oit.duke.edu › jupyternotebooks › 1-Core Python › answers › rq-28-answers.html
Core Python / Dates and Times — Programming for Financial Technology
from datetime import datetime, timezone current_datetime_utc = datetime.now(timezone.utc) print(current_datetime_utc) # This will print the current date and time in UTC ... Explain the concept of time zones in Python’s datetime module and how to handle them.
🌐
Medium
medium.com › @life-is-short-so-enjoy-it › python-datetime-utcnow-maybe-no-more-for-me-221795e8ddbf
python: datetime.utcnow() — maybe no more for me | by Life-is-short--so--enjoy-it | Medium
February 24, 2023 - The output that got my attention was the output of datetime.utcnow().timestamp() which is 1601444278 on UTC+7 timezone. Initially, I thought that maybe the user who answered made a mistake or a typo while having written the answer.
🌐
Astral
docs.astral.sh › ruff › rules › call-datetime-utcnow
call-datetime-utcnow (DTZ003) | Ruff - Astral Docs
import datetime datetime.datetime.now(tz=datetime.timezone.utc) Or, for Python 3.11 and later: import datetime datetime.datetime.now(tz=datetime.UTC) Python documentation: Aware and Naive Objects Back to top
🌐
Simon Willison
til.simonwillison.net › python › utc-warning-fix
Fixes for datetime UTC warnings in Python | Simon Willison’s TILs
December 13, 2024 - According to the documentation datetime.UTC was added in Python 3.11 as an alias for datetime.timezone.utc - so I switched my usage of datetime.utcnow() to the following instead: import datetime utcnow = datetime.datetime.now(datetime.timezone.utc)
🌐
Andrea Grandi
andreagrandi.it › posts › python-now-time-to-migrate-from-utcnow
Python: it is now() time to migrate from utcnow() - Andrea Grandi
July 17, 2024 - 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.
🌐
GitHub
github.com › dbt-labs › dbt-core › issues › 9791
[Bug] `datetime.datetime.utcnow()` is deprecated as of Python 3.12 · Issue #9791 · dbt-labs/dbt-core
March 21, 2024 - Any usage of datetime.datetime.utcnow() ... is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC)....
Author   dataders
🌐
Note.nkmk.me
note.nkmk.me › home › python
Get the Current Date and Time in Python: datetime.now, date.today | note.nkmk.me
April 22, 2025 - The datetime.utcnow() function returns a naive datetime object representing the current UTC time, with its tzinfo attribute set to None. datetime.datetime.utcnow() — Basic date and time types — Python 3.13.3 documentation
🌐
Python Morsels
pythonmorsels.com › converting-to-utc-time
Converting datetime to UTC in Python - Python Morsels
December 20, 2021 - >>> datetime.datetime.utcnow() datetime.datetime(2030, 4, 1, 8, 15, 59, 89013) This method was deprecated in Python 3.12 and the Python documentation recommends passing the target timezone (timezone.utc in our case) to the now method instead: >>> datetime.datetime.now(datetime.timezone.utc) datetime.datetime(2030, 4, 1, 8, 15, 59, 89013, tzinfo=datetime.timezone.utc) Or on Python 3.11+: >>> datetime.datetime.now(datetime.UTC) datetime.datetime(2030, 4, 1, 8, 15, 59, 89013, tzinfo=datetime.timezone.utc) That way you'll end up with a timezone-aware datetime object (see naive and aware objects for more on timezone awareness).
🌐
DEV Community
dev.to › behainguyen › python-local-date-time-and-utc-date-time-4cl7
Python: local date time and UTC date time. - DEV Community
February 11, 2023 - We can see that datetime.astimezone(tz=None) converts a UTC date time into local date time correctly, and the converted value now also has local time zone name; and furthermore, it still retains the original UTC offset value.
🌐
PyPI
pypi.org › project › utcnow
utcnow
JavaScript is disabled in your browser. Please enable JavaScript to proceed · A required part of this site couldn’t load. This may be due to a browser extension, network issues, or browser settings. Please check your connection, disable any ad blockers, or try using a different browser