Problem Statement
Explain naive vs aware datetimes and how to handle time zones in modern Python.
Explanation
A naive datetime has no time zone info, so arithmetic and comparisons can be wrong across regions. An aware datetime carries a tzinfo and knows its offset from UTC, which makes math and conversions correct.
Use zoneinfo (built in) to attach real time zones, convert to UTC for storage, and convert to local zones for display. Always specify a timezone when parsing external timestamps.
Code Solution
SolutionRead Only
from zoneinfo import ZoneInfo
from datetime import datetime
now=datetime.now(tz=ZoneInfo('Asia/Kolkata'))Practice Sets
This question appears in the following practice sets:
