本文是基于Windows系统环境,学习和测试datetime模块:
Windows 10
PyCharm 2018.3.5 for Windows (exe)
python 3.6.8 Windows x86 executable installer
import datetime
today = datetime.date.today()
print(today) # 2019-07-30
formatted_today=today.strftime('%y%m%d')
print(formatted_today) # 190730
import datetime
today = datetime.date.today()
print(today) # 2019-07-30
tomorrow = today + datetime.timedelta(days=1)
print(tomorrow) # 2019-07-31
import datetime
today = datetime.date.today()
print(today) # 2019-07-30
yesterday= today + datetime.timedelta(days=-1)
print(yesterday) # 2019-07-29