日期格式为 YYYYMMDD 而不是 python 中的 YYYY-MM-DD

Date in format of YYYYMMDD rather than YYYY-MM-DD in python

我需要移动的文件具有这样的日期模式:20190328

我的日期时间模块给我的日期是 YYYY-MM-DD。如何获取 YYYYMMDD 格式的日期?

使用strftime:

import datetime
print(datetime.datetime.now().strftime("%Y%m%d"))

输出:

20190328