def dete_to_week(y,m,d): if y>=1990: s=0 for i in range(1990,y): if (y % 400 == 0) or (y % 4 == 0 and y % 100 != 0): s+=366 else: s+=365 s1=s for n in range(1, m): if n in [1, 3, 5, 7, 8, 10, 12]: s1=s1+31 elif n == 2: if (y % 400 == 0) or (y % 4 == 0 and y % 100 != 0): s1=s1+28 else: s1 = s1 + 29 else: s1 = s1 + 30 s1=s1+d x=s1%7 if x > 0: return ("%d年%d月%d日是周%x" % (y, m, d, x)) else: return ("%d年%d月%d日是周日" % (y, m, d,)) str=dete_to_week(2022,4, 23) print (str)
1990年1月1日是星期一,定义函数date_to_week(year,month,day),实现功能输入年月日后返回星期几,例如date_to_week(2022,4,23),返回:星期六。
于 2022-04-23 11:18:24 首次发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)