可以使用Python中的datetime和calendar模块来实现此脚本。以下是代码示例:
import datetime
import calendar
def get_next_date():
today = datetime.date.today()
fifteenth = datetime.date(today.year, today.month, 15)
if fifteenth.weekday() == calendar.SATURDAY:
return fifteenth - datetime.timedelta(days=1)
elif fifteenth.weekday() == calendar.SUNDAY:
return fifteenth - datetime.timedelta(days=2)
else:
return fifteenth
next_date = get_next_date()
print(next_date.strftime("%Y-%m-%d"))
此代码检查今天是否为15号。如果是,它将返回下个月的15号。如果15号是周六或周日,则将在前一个周五执行。该代码返回的日期格式为“YYYY-MM-DD”。
下一篇:编写一个RISC-V的引导程序