๐Ÿค” Python Quiz: Traveling Time Zones in Python ๐Ÿ•”

vladignatyev

Vladimir Ignatev

Posted on December 4, 2023

๐Ÿค” Python Quiz: 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!

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)
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")
print(utc_time)
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.

๐Ÿ’– ๐Ÿ’ช ๐Ÿ™… ๐Ÿšฉ
vladignatyev
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

ยฉ TheLazy.dev

About