from datetime import datetime, timedelta # 获取当前日期 today = datetime.today() # 获取前一天的日期 yesterday = today - timedelta(days=1) # 格式化日期为所需的字符串格式 date_str = yesterday.strftime("%Y-%m-%d") print("前一天的日期是:", date_str)
############################
标签:-%,python,datetime,获取,日期,today,前一天 From: https://www.cnblogs.com/herd/p/17726627.html