python中datetime和timedelta模块的使用

from datetime import datetime, timedelta
dt = datetime.now()
print dt
#输出为:2017-09-04 13:26:29.954000
前一天:yesterday = dt-timedelta(days=1)
#输出为:2017-09-03 13:26:29.954000
后一天:tomorrow = dt+timedelta(days=1)
#输出为:2017-09-05 13:26:29.954000
指定日期 如2017-04-04
dt = datetime(2017,4,4)
#输出为:2017-04-03 00:00:00

你可能感兴趣的:(python中datetime和timedelta模块的使用)