If I need the current UTC in Python, I use datetime.now(timezone.utc) first. It gives me a timezone-aware datetime, which is the safest choice for logs, APIs, databases, and scheduled jobs.
What UTC means
UTC stands for Coordinated Universal Time. It is the standard time reference I use when I want one consistent clock across servers, apps, and users in different locations.
Best way to get UTC
For modern Python, this is the method I recommend:
from datetime import datetime, timezone
utc_now = datetime.now(timezone.utc)
print(utc_now)
Example output:
2026-05-21 04:04:41.071261+00:00
I executed the above example code and added the screenshot below.

This is timezone-aware, which means Python knows the value is in UTC.
Why I prefer this method
I prefer datetime.now(timezone.utc) because it creates an aware datetime object. That matters because naive datetimes can be misread as local time in other parts of a program.
A UTC-aware value is better when I:
- Save timestamps in a database.
- Write application logs.
- Call external APIs.
- Compare times across time zones.
- Schedule tasks reliably.
Avoid utcnow() for new code
You may see datetime.utcnow() in older tutorials. I do not recommend it for new code because it returns a naive datetime, not an aware one.
from datetime import datetime
utc_now = datetime.utcnow()
print(utc_now)
This can look like UTC, but Python does not attach timezone information to it. That is why datetime.now(timezone.utc) is the better choice.
Get UTC as a string
If I want a readable UTC string, I format it with strftime().
from datetime import datetime, timezone
utc_now = datetime.now(timezone.utc)
formatted = utc_now.strftime("%Y-%m-%d %H:%M:%S UTC")
print(formatted)
Example output:
2026-05-21 04:13:27 UTC
I executed the above example code and added the screenshot below.

This is useful for reports, email templates, and audit logs.
Get UTC date only
Sometimes I only need the date in UTC.
from datetime import datetime, timezone
utc_date = datetime.now(timezone.utc).date()
print(utc_date)
Example output:
2026-05-21
I executed the above example code and added the screenshot below.

Convert local time to UTC
If I already have a timezone-aware local datetime, I can convert it to UTC with astimezone().
from datetime import datetime, timezone
from zoneinfo import ZoneInfo
new_york_time = datetime.now(ZoneInfo("America/New_York"))
utc_time = new_york_time.astimezone(timezone.utc)
print("New York:", new_york_time)
print("UTC:", utc_time)
This is the pattern I use when I receive time in a local timezone and need to normalize it.
UTC vs local time
Here is the simple rule I follow:
- Use UTC for storage and processing.
- Use local time only for display.
That keeps my app predictable. If I store everything in UTC, I can convert it later for a user in New York, Los Angeles, or Chicago without changing the original value.
Naive vs aware datetime
This topic matters more than most beginners realize.
A naive datetime has no timezone attached. An aware datetime includes timezone information.
from datetime import datetime, timezone
naive_time = datetime.now()
aware_time = datetime.now(timezone.utc)
print(naive_time)
print(aware_time)
When I work with UTC, I want the aware version. That avoids confusion and makes comparisons safer.
Timezone-aware UTC example
If I want a clean UTC timestamp for an order record, I use this:
from datetime import datetime, timezone
order_created_at = datetime.now(timezone.utc)
print("Order created at:", order_created_at)
That gives me a value I can store and compare anywhere without worrying about the user’s local clock.
Common mistakes
These are the mistakes I try to avoid:
- Using datetime.utcnow() in new code.
- Storing local time when UTC would be safer.
- Mixing naive and aware datetime objects.
- Formatting too early instead of keeping the raw UTC value for processing.
- Assuming UTC and local time are the same thing.
If I keep the data aware and convert only when needed, the code stays cleaner.
When I use UTC
I use UTC for:
- API timestamps.
- Database audit fields.
- Background jobs.
- Distributed systems.
- Error logs.
- Message queues.
I use local time only when a person needs to read it in their own timezone.
One complete example
Here is a small example I can reuse in real projects:
from datetime import datetime, timezone
from zoneinfo import ZoneInfo
utc_now = datetime.now(timezone.utc)
la_time = utc_now.astimezone(ZoneInfo("America/Los_Angeles"))
print("UTC:", utc_now)
print("Los Angeles:", la_time)
print("UTC formatted:", utc_now.strftime("%Y-%m-%d %H:%M:%S UTC"))
This shows the same moment in UTC and in a US timezone.
Final thoughts
If I want the current UTC in Python, I use datetime.now(timezone.utc) because it is modern, clear, and timezone-aware. If I need to show the time to a user, I convert UTC to their local timezone at the last step.
You may also like to read:
- Make a .exe from a Python Script with PyInstaller
- Exit Function in Python
- Python Stdin, Stdout, and Stderr
- Switch Case in Python with User Input

Bijay Kumar is an experienced Python and AI professional who enjoys helping developers learn modern technologies through practical tutorials and examples. His expertise includes Python development, Machine Learning, Artificial Intelligence, automation, and data analysis using libraries like Pandas, NumPy, TensorFlow, Matplotlib, SciPy, and Scikit-Learn. At PythonGuides.com, he shares in-depth guides designed for both beginners and experienced developers. More about us.