Skip to main content

localtime

Convert an aware datetime.datetime to local time.

Only aware datetimes are allowed. When value is omitted, it defaults to now().

Local time is defined by the current time zone, unless another time zone is specified.

def localtime(
value: datetime.datetime = None,
timezone: datetime.tzinfo = None
) - > datetime.datetime

Convert an aware datetime.datetime to local time. Only aware datetimes are allowed. When value is omitted, it defaults to now(). Local time is defined by the current time zone, unless another time zone is specified.

Parameters

NameTypeDescription
valuedatetime.datetime = NoneThe aware datetime object to be converted; defaults to the current time if not provided.
timezonedatetime.tzinfo = NoneThe target timezone for conversion; defaults to the currently active timezone if not specified.

Returns

TypeDescription
datetime.datetimeThe datetime object converted to the target timezone, maintaining its point in time but adjusted for the local offset.