จักรยานออกเดินทางกี่โมง? (ฉบับทั่วโลก)
เมื่อต้องการแปลง datetime จาก timezone หนึ่งไปยังอีก timezone หนึ่ง ให้ใช้ .astimezone() และ tz โดยทั่วไปมักจะแปลงเป็น UTC แต่คราวนี้ลองแปลงจาก 'America/New_York' ไปยัง timezone ต่าง ๆ ทั่วโลกกัน
แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร
การทำงานกับวันที่และเวลาใน Python
แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ
ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์
# Create the timezone object
uk = ____
# Pull out the start of the first trip
local = onebike_datetimes[0]['start']
# What time was it in the UK?
notlocal = local.____(____)
# Print them out and see the difference
print(local.isoformat())
print(notlocal.isoformat())