C语言怎么计算任意一天事星期几,Zeller 公式:计算任意一天是星期几

本文详细介绍了Zeller公式,用于计算给定日期(包括公元后1582年10月15日前)在格里高利历下的星期几,涉及世纪、世纪内的年份、月份和日期。公式适用于历史日期的星期推算,特别注意了1582年改革前的特殊情况。
摘要由CSDN通过智能技术生成

标签:

Zeller's Formula:

For the Gregorian calendar, Zeller's Formula is

\[\displaystyle W=\left(\left\lfloor \frac{C}{4} \right\rfloor -2C+Y+\left\lfloor \frac{Y}{4} \right\rfloor +\left\lfloor \frac{26(M+1)}{10} \right\rfloor +D-1\right)\bmod 7. \]

Where

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

\(C\): the zero-based century. (actually \(\lfloor \text{year}/100\rfloor\approx \text{century}-1\))

\(Y\): the year of the century. (\(\text{year}\bmod 100\))

\(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 algorithm 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(\left\lfloor \frac{C}{4} \right\rfloor -2C+Y+\left\lfloor \frac{Y}{4} \right\rfloor +\left\lfloor \frac{26(M+1)}{10} \right\rfloor +D+3 \right)\bmod 7.\]

标签:

来源: https://www.cnblogs.com/greyqz/p/9780805.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值