Here's a simple one-liner. I've verified this for all the years 1901-2200 using Excel, and 1582-3000 using Python's datetime
.
dayOfWeek = (year*365 + trunc((year-1) / 4) - trunc((year-1) / 100) +
trunc((year-1) / 400)) % 7
This will give the day of the week as 0 = Sunday, 6 = Saturday. This result can easily be adjusted by adding a constant before or after the modulo 7. For example to match Python's convention of 0 = Monday, add 6 before the modulo.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…