Zeller 公式:计算任意一天是星期几

Zeller's Formula:

For the Gregorian calendar, Zeller's Formula is

[displaystyle W=left(leftlfloor frac{C}{4} ight floor -2C+Y+leftlfloor frac{Y}{4} ight floor +leftlfloor frac{26(M+1)}{10} ight floor +D-1 ight)mod 7. ]


Where

(W): the day of week. ((0 =) Sunday, (1 =) Monday, ..., (5 =) Friday, (6 =) Saturday)

(C): the zero-based century. ((=lfloor ext{year}/100 floor= ext{century}-1))

(Y): the year of the century. ((=egin{cases} ext{year}mod 100, & M=3,4,ldots,12, \ ( ext{year}-1)mod 100, & M=13,14.end{cases} ​))

(M): the month. ((3 =) March, (4 =) April, (5 =) May, ..., (14 =) February)

(D): the day of the month.


NOTE: In this formula January and February are counted as months 13 and 14 of the previous year. E.g. if it is 2010/02/02, the formula counts the date as 2009/14/02.


For the day before 1582/10/15, notice that the time period from 1582/10/05 to 1582/10/14 does not exists. So for the day before 1582/10/15, the formula is

[displaystyle W=left(leftlfloor frac{C}{4} ight floor -2C+Y+leftlfloor frac{Y}{4} ight floor +leftlfloor frac{26(M+1)}{10} ight floor +D+3 ight)mod 7. ]



Post author 作者: Grey
Copyright Notice 版权说明: Except where otherwise noted, all content of this blog is licensed under a CC BY-NC-SA 4.0 International license. 除非另有说明,本博客上的所有文章均受 知识共享署名 - 非商业性使用 - 相同方式共享 4.0 国际许可协议 保护。
原文地址:https://www.cnblogs.com/greyqz/p/9780805.html