给你一个字符串
date
,按YYYY-MM-DD
格式表示一个 现行公元纪年法 日期。返回该日期是当年的第几天。
class Solution:
def dayOfYear(self, date: str) -> int:
year, month, day = map(int, date.split('-'))
days = [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[1] = 29
i = 0
_sum = day
while i < month - 1:
_sum += days[i]
i += 1
return _sum
if __name__ == '__main__':
print(Solution().dayOfYear("2000-03-09"))