datetime.now() reads the system clock and returns the current date and time as a new datetime object, down to the microsecond (the real precision depends on the operating system).
With no argument the result is naive local time: tzinfo is None. Pass a tzinfo such as timezone.utc and you get an aware datetime for that zone, which is the safe choice for logs, databases, and APIs. It is the modern replacement for the deprecated utcnow().
datetime.now() is a classmethod of datetime.datetime: call it on the class itself, as datetime.now(...), and it returns a new object. Import the class first, for example from datetime import datetime.
Syntax
Call it on the datetime class, optionally passing a time zone.
python
moment = datetime.now()
moment = datetime.now(tz)
moment = datetime.now(timezone.utc)
Call
What it does
datetime.now()
Gives the current local date and time as a naive datetime (tzinfo is None).
datetime.now(timezone.utc)
Gives the current time in UTC as an aware datetime whose tzinfo is timezone.utc.
datetime.now(tz=ist)
Gives the current wall-clock time at the fixed offset stored in ist, also aware.
Every call reads the clock again, so two calls almost never return the same value. Save the result in a variable when you need one consistent moment.
Method signatures
python
classmethod datetime.now(tz=None)
# tz: None or a tzinfo instance (keyword or positional)
# returns: datetime (naive if tz is None, aware otherwise)
Parameters
Parameter
Description
tz
Optional. A tzinfo object such as timezone.utc or timezone(timedelta(hours=5, minutes=30)). Default None means local time without a zone.
Return Value
Return Value
Description
datetime
The current moment. Naive local time when tz is None; aware time in zone tz otherwise.
Python Examples
Example 1 — Get the Current Time as an Aware UTC datetime
Ask for the current moment in UTC and inspect the fixed parts of the result. The clock value itself is never printed, so the output is the same on every run.
Classmethod call.datetime.now(timezone.utc) is called on the class and returns a brand-new datetime instance.
Zone attached. Because a tzinfo was passed, stamp.tzinfo is timezone.utc, which prints as UTC.
Zero offset.utcoffset() returns timedelta(0), and a zero timedelta prints as 0:00:00.
Sanity check, not a timestamp. Comparing the year with 2024 gives a stable True instead of printing the changing date.
Example 2 — Measure How Long a Task Took
Read the clock before and after some work and subtract the two aware values. The difference is a timedelta; only stable facts about it are printed.
python
from datetime import datetime, timedelta, timezone
start = datetime.now(timezone.utc)
total = sum(n * n for n in range(100000))
end = datetime.now(timezone.utc)
elapsed = end - start
print(total)
print(type(elapsed).__name__)
print(elapsed >= timedelta(0))
print(elapsed < timedelta(minutes=1))
Output
333328333350000
timedelta
True
True
How It Works
Two clock readings.start and end are taken before and after the loop that sums the squares of 0 to 99999.
Subtraction gives a duration.end - start between two aware datetimes returns a timedelta, not a number.
Stable checks. The exact duration varies per run, so the program only checks that it is not negative and is under one minute.
Benchmark tip. For precise timing prefer time.perf_counter(); it never jumps when the system clock is corrected.
Example 3 — Read the Clock in a Fixed UTC Offset
Get the current time at UTC+05:30, convert it to UTC, and confirm both objects describe the same instant.
Offset object.timezone(timedelta(hours=5, minutes=30)) is a fixed offset with no name, so its tzname() is generated as UTC+05:30.
Aware reading.datetime.now(ist) returns the wall-clock time at that offset with the zone attached.
Same instant.astimezone() changes the clock reading but not the moment, so == between the two aware values is True.
Offset as text. The %z code prints the offset as +0530, whatever the current time is.
Frequently Asked Questions
Use datetime.now(timezone.utc) after from datetime import datetime, timezone. It returns an aware datetime whose tzinfo is UTC.
With no argument they return the same naive local time. now() also accepts a tz argument, so it can return an aware datetime; today() cannot.
Without tz, now() uses the computer's local time zone. A server set to UTC and a laptop set to IST print different values. Pass timezone.utc to get the same zone everywhere.
You wrote import datetime, so datetime is the module. Call datetime.datetime.now(), or change the import to from datetime import datetime.
It works for rough timing, but the wall clock can be adjusted. time.perf_counter() is monotonic and more precise for benchmarks.