测试计算所有下一天日期的函数nextDate():
时间: 2024-01-22 17:20:18 浏览: 30
好的,下面是一个Python实现的nextDate()函数:
```python
def nextDate(year, month, day):
days_in_month = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] # 月份对应的天数
# 判断是否为闰年
if (year % 4 == 0 and year % 100 != 0) or year % 400 == 0:
days_in_month[1] = 29 # 闰年二月有29天
# 判断输入日期是否合法
if month < 1 or month > 12 or day < 1 or day > days_in_month[month - 1]:
return "Invalid date"
# 计算下一天日期
if day < days_in_month[month - 1]:
return year, month, day + 1
else:
if month < 12:
return year, month + 1, 1
else:
return year + 1, 1, 1
```
这个函数的输入参数为年份、月份和日期,输出为下一天的日期(以元组的形式返回)。函数首先判断输入的年份是否为闰年,如果是,则将二月的天数赋为29天。然后判断输入的日期是否在合法范围内,如果不是,则返回"Invalid date"。最后根据当前日期计算下一天的日期,并返回。