利用datetime模組進行不同時間單位的換算
from datetime import timedelta a = timedelta(days=2, hours=6) b = timedelta(hours=4.5) c = a + b print(c.days) print(c.seconds) print(c.seconds / 3600)
表示特定的日期和時間
from datetime import datetime a = datetime(2016, 8, 30) print(a + timedelta(days=10)) b = datetime(2016, 9, 30) d = b - a print(d.days) now = datetime.today() print(now) print(now + timedelta(minutes=10))
datetime模組可以正確處理閏年 ,計算節日的日期等可以用dateutil模組