Skip to main content

localize

Convert aware :class:~datetime.datetime to another timezone.

Using a ZoneInfo timezone will give the most flexibility in terms of ambiguous DST handling.

def localize(
dt: datetime,
tz: tzinfo
) - > datetime

Convert aware :class:~datetime.datetime to another timezone. Using a ZoneInfo timezone will give the most flexibility in terms of ambiguous DST handling.

Parameters

NameTypeDescription
dtdatetimeThe datetime object to be localized; if naive, it will be made aware using the provided timezone.
tztzinfoThe target timezone information used for localization or conversion.

Returns

TypeDescription
datetimeThe timezone-aware datetime object converted to the target timezone.