Golang:
思路:这题向我们展示了学数学的如何杀人诛心!!!让我们记住这个公式:基姆拉尔森计算公式,W=(d+2m+3(m+1)/5+y+y/4-y/100+y/400+1)%7,注意,1月份看成13月份,2月份看成14月份,比如2019-01-21应该被视作2018-13-21来计算。
代码如下:
func dayOfTheWeek(day int, month int, year int) string {
res:=[]string{"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"}
if month==1{
month=13
year--
}
if month==2{
month=14
year--
}
return res[(day+2*month+3*(month+1)/5+year+year/4-year/100+year/400+1)%7]
}
有疑问加站长微信联系(非本文作者)