Python datetime.now() Method

Beginner
6 min read
Updated: Nov 2026
3 examples
classmethod

Definition

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)
CallWhat 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

ParameterDescription
tzOptional. 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 ValueDescription
datetimeThe 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.

python
from datetime import datetime, timezone

stamp = datetime.now(timezone.utc)

print(type(stamp).__name__)
print(stamp.tzinfo)
print(stamp.utcoffset())
print(stamp.year >= 2024)

How It Works

  1. Classmethod call. datetime.now(timezone.utc) is called on the class and returns a brand-new datetime instance.
  2. Zone attached. Because a tzinfo was passed, stamp.tzinfo is timezone.utc, which prints as UTC.
  3. Zero offset. utcoffset() returns timedelta(0), and a zero timedelta prints as 0:00:00.
  4. 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))

How It Works

  1. Two clock readings. start and end are taken before and after the loop that sums the squares of 0 to 99999.
  2. Subtraction gives a duration. end - start between two aware datetimes returns a timedelta, not a number.
  3. Stable checks. The exact duration varies per run, so the program only checks that it is not negative and is under one minute.
  4. 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.

python
from datetime import datetime, timedelta, timezone

ist = timezone(timedelta(hours=5, minutes=30))
local_ist = datetime.now(ist)
utc_now = local_ist.astimezone(timezone.utc)

print(local_ist.tzname())
print(local_ist.utcoffset())
print(utc_now.tzname())
print(local_ist == utc_now)
print(local_ist.strftime("%z"))

How It Works

  1. Offset object. timezone(timedelta(hours=5, minutes=30)) is a fixed offset with no name, so its tzname() is generated as UTC+05:30.
  2. Aware reading. datetime.now(ist) returns the wall-clock time at that offset with the zone attached.
  3. Same instant. astimezone() changes the clock reading but not the moment, so == between the two aware values is True.
  4. 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.

Next: datetime.replace()

Return a copy with some fields changed, such as year, hour, or tzinfo.

replace() →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

11 people found this page helpful