Skip to main content

time_as_tzinfo

No overview available.

def time_as_tzinfo(
dt: datetime,
tz: str = None
) - > datetime

Converts a datetime object to a specific timezone or the system local timezone if none is provided. Use this to ensure consistent timezone-aware datetime objects for comparison or storage.

Parameters

NameTypeDescription
dtdatetimeThe datetime object to be converted or localized.
tzstr = NoneThe target timezone name (e.g., 'UTC', 'US/Eastern'); if None, the system's local timezone is used.

Returns

TypeDescription
datetimeA timezone-aware datetime object adjusted to the specified timezone.