自行车是什么时间出发的?(全球版)
当您需要将一个 datetime 从一个时区转换到另一个时区时,请使用 .astimezone() 和 tz。您通常会把时间转换到 UTC,但这次我们来试试把 'America/New_York' 转到几个不同的时区,增加一些趣味。
本练习是课程的一部分
在 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())