Python 获取去年一月一号日期
要获取去年一月一号的日期,你可以使用datetime模块中的date类。首先,导入datetime模块,然后使用date类的构造函数来创建一个表示去年一月一号的日期对象。以下是一个示例代码:
import datetime
last_year = datetime.date.today().year - 1
jan_1st_last_year = datetime.date(last_year, 1, 1)
print(jan_1st_last_year)
此代码将打印去年一月一号的日期,格式为YYYY-MM-DD。
原文地址: https://www.cveoy.top/t/topic/qhTK 著作权归作者所有。请勿转载和采集!