DEV Community

Vladimir Ignatev
Vladimir Ignatev

Posted on

🤔 Python Quiz 7/64: Traveling Time Zones in Python 🕔

The topic for todays quiz is "Handling Time Zones in Python" covered by PEP 431 and PEP 495. These PEPs discuss improvements in timezone support in Python's datetime module, making it a relevant and somewhat challenging topic for beginners.

Follow me to learn 🐍 Python in 5-minute a day fun quizzes!


Which code sample correctly handles time zones in Python?

Sample 1

from datetime import datetime, timezone

utc_time = datetime(2023, 12, 3, 10, 0, 0, tzinfo=timezone.utc)
local_time = utc_time.astimezone()
Enter fullscreen mode Exit fullscreen mode

Sample 2

from datetime import datetime

local_time = datetime(2023, 12, 3, 10, 0, 0)
utc_time = local_time.astimezone("UTC")
Enter fullscreen mode Exit fullscreen mode

Post your answer in the comments – is it 0 for the first sample or 1 for the second! As usual, the correct answer will be explained in a comment.

Top comments (0)