๐ค Python Quiz: Traveling Time Zones in Python ๐
Vladimir Ignatev
Posted on December 4, 2023
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!
Quiz
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()
print(local_time)
Sample 2
from datetime import datetime
local_time = datetime(2023, 12, 3, 10, 0, 0)
utc_time = local_time.astimezone("UTC")
print(utc_time)
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.
๐ ๐ช ๐
๐ฉ
Vladimir Ignatev
Posted on December 4, 2023
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.
Related
githubcopilot AI Innovations at Microsoft Ignite 2024 What You Need to Know (Part 2)
November 29, 2024