Setting timezones
Now that you have the hang of setting timezones one at a time, let's look at setting them for the first ten trips that W20529 took.
timezone and timedelta have already been imported. Make the change using .replace()
Latihan ini adalah bagian dari kursus
Working with Dates and Times in Python
Petunjuk latihan
- Create
edt, atimezoneobject whose UTC offset is -4 hours. - Within the
forloop: - Set the
tzinfofortrip['start']. - Set the
tzinfofortrip['end'].
Latihan interaktif praktis
Cobalah latihan ini dengan menyelesaikan kode contoh berikut.
# Create a timezone object corresponding to UTC-4
edt = ____
# Loop over trips, updating the start and end datetimes to be in UTC-4
for trip in onebike_datetimes[:10]:
# Update trip['start'] and trip['end']
trip['start'] = trip['start'].____
trip['end'] = trip['end'].____