เริ่มต้นใช้งานเริ่มต้นใช้งานได้ฟรี

จักรยานออกเดินทางกี่โมง? (ฉบับทั่วโลก)

เมื่อต้องการแปลง 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())
แก้ไขและรันโค้ด