目錄python
# datetime模塊能夠當作是時間加減的模塊 import datetime
# 返回當前時間 import datetime print(datetime.datetime.now()) # 2019-08-23 19:53:53.742850
#輸出是那一天 import datetime import time print(datetime.date.fromtimestamp(time.time())) # 2019-08-23
#當天時間加三日 import datetime import time print(datetime.datetime.now()+datetime.timedelta(3)) # 2019-08-26 19:56:13.500102
#當天時間減三天 import datetime import time print(datetime.datetime.now()+datetime.timedelta(-3)) # 2019-08-20 19:57:18.572635
# 當天時間減3小時 import datetime import time print(datetime.datetime.now()+datetime.timedelta(hours=3)) # 2019-08-23 22:58:41.294881
# 時間替換 import datetime import time c_time = datetime.datetime.now() print(c_time.replace(minute=20,hour=5,second=13)) # 2019-08-23 05:20:13.829892