Python Function Reference

datetime.datetime.now

Get the current date and time.

Python 3.13
datetime.datetime.now(tz=None)

Parameters

tztzinfo | Noneoptional
A time zone such as timezone.utc; without it, local time without a time zone is returned.

Return value

A datetime object with the current date and time.

Examples

Local time without a time zone

Python 3.13
from datetime import datetime

now = datetime.now()
print(isinstance(now, datetime), now.tzinfo)
True None

Current time in UTC

Python 3.13
from datetime import datetime, timezone

now = datetime.now(timezone.utc)
print(now.tzinfo, now.utcoffset())
UTC 0:00:00

Details

Without tz, the result has no time zone (tzinfo is None), and it cannot be subtracted from dates with a time zone or compared with them using greater or less than; that raises TypeError. For time that is stored or passed between systems, use datetime.now(timezone.utc).

See also

Where to learn