1 import datetime 2 from datetime import datetime, timedelta 3 4 now = datetime.now() 5 mydt = datetime(1997,9,12) 6 print(now,mydt) 7 8 9 print((mydt - now).days) 10 print(now + timedelta(hours=72)) 11 print(now - timedelta(days=100)) 12 print(now - timedelta(weeks=1))
运行结果: