開始使用免費開始

設定時區

既然你已經能一次設定一個時區了,接下來來看看如何為車號 W20529 的前 10 段行程設定時區。

timezonetimedelta 已經匯入。請使用 .replace() 來完成變更。

本練習屬於課程

在 Python 處理日期與時間

檢視課程

練習說明

  • 建立 edt,這是一個 UTC 位移為 -4 小時的 timezone 物件。
  • for 迴圈中:
  • 設定 trip['start']tzinfo
  • 設定 trip['end']tzinfo

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

# 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'].____
編輯並執行程式碼