# 确定星期几

确定星期几，是指仅凭一个日历日期，推算出它落在一周七天中的哪一天的问题。由于星期的运行独立于月份和年份的周期，答案可以归结为模7的模运算；从卡尔·弗里德里希·高斯（Carl Friedrich Gauss）1800年的方法到约翰·康威（John Conway）1973年的末日规则，一系列算法利用格里高利历的结构，使计算快到足以心算完成。

| 关键事实 | 详情 |
|---|---|
| 日历周期 | 格里高利历每400年精确重复一次：其周期包含146,097天，能被7整除，因此星期模式每隔四个世纪重复一次<sup>[1](https://eclipse.gsfc.nasa.gov/SEhelp/calendars.html)</sup> |
| 最早发表的公式 | 克里斯蒂安·蔡勒（Christian Zeller）于1882、1883、1885和1886年发表了星期几公式和复活节公式，同时适用于格里高利历和儒略历<sup>[2](https://people.cs.nycu.edu.tw/~tsaiwn/sisc/runtime_error_200_div_by_0/www.merlyn.demon.co.uk/zeller-c.htm)</sup> |
| 心算里程碑 | 刘易斯·卡罗尔（Lewis Carroll）1887年发表于《自然》（*Nature*）的算法是首个专为心算设计的算法；他能在约20秒内算出一个日期的星期几<sup>[3](https://www.scientificamerican.com/article/calendar-algorithm/)</sup> |
| 末日规则 | 约翰·霍顿·康威（John Horton Conway）于1973年在《尤里卡》（*Eureka*）第36期第28–31页以《明天是末日的第二天》（"Tomorrow is the Day After Doomsday"）为题发表了末日规则<sup>[4](https://people.sc.fsu.edu/~jburkardt/f77_src/doomsday/doomsday.html)</sup> |
| 末日日期 | 4/4、5/9、6/6、7/11、8/8、9/5、10/10、11/7、12/12，以及二月的最后一天，每年都落在同一个星期几<sup>[5](https://people.csail.mit.edu/ddeford/Crossroads_pdfs/Date_Methods.pdf)</sup> |
| 世纪锚点 | 格里高利历的锚定日：1800年代为星期五，1900年代为星期三，2000年代为星期二，2100年代为星期日<sup>[6](https://www.timeanddate.com/date/doomsday-weekday.html)</sup> |
| 软件形式 | 编程库依据前推格里高利历计算星期几，即在整个时间轴上统一适用当今的闰年规则<sup>[7](https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/time/LocalDate.html)</sup> |

## 为什么这个问题可解

两个结构性事实使星期几的计算成为可能。第一，七日一周连续运行，不受月份长短或闰年的影响，因此每个日期都映射到七日周期中的一个固定位置。第二，格里高利历是周期性的：400年跨度包含146,097天，恰好是7的整数倍，因此包括闰年模式在内的整个日历在400年后重复<sup>[1](https://eclipse.gsfc.nasa.gov/SEhelp/calendars.html)</sup>。因此，算法只需足够覆盖一个400年周期的数据，任何日期都可以在计算前对400取模化简。

年度漂移也很简单。平年365天使某个固定日期的星期几前进1（365 ≡ 1 mod 7），闰年366天则前进2。下面每一种方法，都是把这种累积漂移加上月间偏移，组织成少数几个简单步骤的方式。

## 蔡勒同余式

来自马克格勒宁根的德国数学家克里斯蒂安·蔡勒在19世纪80年代的一系列论文中发表了他的同余式。在1886年的表述中，以J为世纪数，K为世纪内的年份，m为月份数，q为月内日期，一月和二月被视为上一年的第13和第14个月，星期几h为格里高利历求和式对7取余的结果<sup>[8](https://people.cs.nycu.edu.tw/~tsaiwn/sisc/runtime_error_200_div_by_0/www.merlyn.demon.co.uk/zel-1886.htm)</sup>：

\[ h = \left( q + \left\lfloor \frac{(m+1) \cdot 26}{10} \right\rfloor + K + \left\lfloor \frac{K}{4} \right\rfloor + \left\lfloor \frac{J}{4} \right\rfloor - 2J \right) \bmod 7. \]

蔡勒的演算示例给出1492年10月12日（儒略历）为星期五，1712年1月24日——腓特烈二世的生日——为星期日<sup>[8](https://people.cs.nycu.edu.tw/~tsaiwn/sisc/runtime_error_200_div_by_0/www.merlyn.demon.co.uk/zel-1886.htm)</sup>。项\( \lfloor (m+1) \cdot 26 / 10 \rfloor \)编码了月份长度，\( K \)和\( \lfloor K/4 \rfloor \)项编码了年度漂移和闰年漂移，\( J \)项编码了世纪修正。由于格里高利历是1582年制定的，蔡勒的算法对于该年之前的日期是否给出历史上正确的星期几，尚不清楚<sup>[9](https://faculty.cs.niu.edu/~hutchins/csci297p2/webpages/zeller.htm)</sup>。

## 高斯与卡罗尔

星期几计算的研究可追溯到卡尔·弗里德里希·高斯，他以1月1日为锚定日，给出了该锚定日星期几的公式，再加上目标日期与它在年内的日数差<sup>[10](https://link.springer.com/article/10.1007/s00283-022-10229-3)</sup>。《爱丽丝漫游奇境记》（*Alice's Adventures in Wonderland*）的作者、严肃的业余数学家刘易斯·卡罗尔于1887年3月31日在《自然》上发表了另一种方法，选择一个虚拟的“3月0日”作为他的锚点<sup>[11](https://www.nature.com/articles/035517a0)</sup><sup> • </sup><sup>[10](https://link.springer.com/article/10.1007/s00283-022-10229-3)</sup>。在卡罗尔之前已有许多日历算法，但他是第一个设计出适合心算的算法的人，他能在脑中用约20秒完成计算<sup>[3](https://www.scientificamerican.com/article/calendar-algorithm/)</sup>。

卡罗尔的方法在此后一个世纪里一直是该领域的基础：康威后来给出的年度锚定日公式与卡罗尔的本质相同<sup>[10](https://link.springer.com/article/10.1007/s00283-022-10229-3)</sup>。

## 康威的末日规则

数学家约翰·霍顿·康威还以发明“生命游戏”元胞自动机而闻名，他于1973年10月在剑桥期刊《尤里卡》上发表了末日规则<sup>[4](https://people.sc.fsu.edu/~jburkardt/f77_src/doomsday/doomsday.html)</sup><sup> • </sup><sup>[12](https://xlinux.nist.gov/dads/HTML/doomsday.html)</sup>。《科学美国人》长期专栏作家、卡罗尔研究者马丁·加德纳（Martin Gardner）把卡罗尔的算法告诉了康威，并挑战他设计一个更简单的算法<sup>[3](https://www.scientificamerican.com/article/calendar-algorithm/)</sup>。

该规则依赖一组易于记忆的日期，即“末日”，它们在任意给定年份中都落在同一个星期几：4/4、6/6、8/8、10/10和12/12（重复数字），加上5/9、9/5、7/11和11/7，可用口诀“Working 9 to 5 at the 7-Eleven”记忆，再加上二月的最后一天<sup>[3](https://www.scientificamerican.com/article/calendar-algorithm/)</sup><sup> • </sup><sup>[5](https://people.csail.mit.edu/ddeford/Crossroads_pdfs/Date_Methods.pdf)</sup>。

2. 由锚点计算该年的末日。以y为年份的后两位数字，经典步骤取\( \lfloor y/12 \rfloor \)、余数\( y \bmod 12 \)和\( \lfloor (y \bmod 12)/4 \rfloor \)，将它们加到锚点上，再对7取模<sup>[6](https://www.timeanddate.com/date/doomsday-weekday.html)</sup>。
3. 选出最接近目标日期的末日，从它开始数天数（模7）。

例如，对于1978年2月11日：12除78得6，余数为6，4除6得1；加上1900年代的锚点（星期三，编号3）得到6 + 6 + 1 + 3 = 16，化简为2，即星期二。因此1978年二月的最后一天（28日，因为1978年不是闰年）是星期二，2月14日是星期二，2月11日是星期六<sup>[6](https://www.timeanddate.com/date/doomsday-weekday.html)</sup>。

康威每天练习；在1999年《科学美国人》的一篇人物报道中，他的电脑用随机日期考他，他通常能在两秒内作答<sup>[3](https://www.scientificamerican.com/article/calendar-algorithm/)</sup>。

## 改进与替代方法

后来的几种方法重新组织了年度计算以提高速度。由空军理工学院的迈克尔·K·沃尔特斯（Michael K. Walters）与一位合著者发表的“奇数+11”法，用更少的除法和记忆替代了经典末日年度计算中除法繁重的步骤<sup>[3](https://www.scientificamerican.com/article/calendar-algorithm/)</sup>。加速类论文提出用作用于两位年份各个十进制数字的表达式，替代康威的\( \lfloor x/12 \rfloor + x \bmod 12 + \lfloor (x \bmod 12)/4 \rfloor \)项，理由是逐位运算更便于心算<sup>[13](https://arxiv.org/abs/1006.3913)</sup>。东京都市大学的仲井博文（Hirofumi Nakai）于2022年给出了一个只使用除法余数的末日公式，\( g(n) = 5(c_{2}+y_{2}-1) + 10y \)对7取模，其中\( c_2 \)和\( y_2 \)分别是世纪和年份除以4的余数，他主张这比同时需要商和余数的公式需要记忆的项更少<sup>[10](https://link.springer.com/article/10.1007/s00283-022-10229-3)</sup>。

对于机器而非人脑，紧凑的直接公式占主导地位。坂本（Sakamoto）方法使用一个12项的月份偏移表计算\( (y + \lfloor y/4 \rfloor - \lfloor y/100 \rfloor + \lfloor y/400 \rfloor + t[m-1] + d) \bmod 7 \)，这种形式适合高吞吐量的微控制器和C语言操作系统内核<sup>[14](https://github.com/ajcr/doomsday)</sup>。零日算法（2014年）用一组为便于记忆的模式而选择的零日来修改康威的规则，例如轮转的奇数日期3/5、5/7、7/9、9/3，以及偶数日期2/12、12/10、10/8、8/6、6/4、4/2<sup>[15](https://arxiv.org/abs/1404.2510)</sup>。

## 日历背景与局限

所有这些算法都假定使用单一连续的日历。格里高利历由教皇格里高利十三世于1582年引入，首先在意大利、西班牙、波兰和葡萄牙实施，1582年10月4日之后直接是10月15日<sup>[16](https://time.com/4517862/google-doodle-gregorian-calendar-anniversary/)</sup>。英国及其殖民地一直沿用儒略历，直到1752年9月，9月2日之后直接是9月14日，跳过了11天，法定新年也从3月25日移至1月1日<sup>[17](https://libguides.ctstatelibrary.org/hg/colonialresearch/calendar)</sup>。

在软件中，这种模糊性通过约定消除：ISO 8601标准将日期表示固定为YYYY-MM-DD<sup>[18](https://www.iso.org/iso-8601-date-and-time-format.html)</sup>，而Java的`LocalDate`等库使用前推格里高利历，在整个时间轴上适用当今的闰年规则。这对于1582年之前的日期在历史上并不准确，但对ISO-8601标准而言是正确的；需要历史上准确星期几的应用必须单独处理日历转换<sup>[7](https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/time/LocalDate.html)</sup>。

## References

1. [Calendars and their History, NASA Eclipse Web Site](https://eclipse.gsfc.nasa.gov/SEhelp/calendars.html)
2. [Zeller's Calendrical Works, J R Stockton](https://people.cs.nycu.edu.tw/~tsaiwn/sisc/runtime_error_200_div_by_0/www.merlyn.demon.co.uk/zeller-c.htm)
3. [What Day Is Doomsday? How to Mentally Calculate the Day of the Week for Any Date, Scientific American](https://www.scientificamerican.com/article/calendar-algorithm/)
4. [doomsday (Fortran code and bibliography), John Burkardt, Florida State University](https://people.sc.fsu.edu/~jburkardt/f77_src/doomsday/doomsday.html)
5. [Date Methods: Doomsday Method and Zeller's Congruence, ACM Crossroads PDF](https://people.csail.mit.edu/ddeford/Crossroads_pdfs/Date_Methods.pdf)
6. [The Doomsday Algorithm, timeanddate.com](https://www.timeanddate.com/date/doomsday-weekday.html)
7. [LocalDate (Java SE 16 API documentation), Oracle](https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/time/LocalDate.html)
8. [On Zeller's 1886 Paper (English translation), J R Stockton](https://people.cs.nycu.edu.tw/~tsaiwn/sisc/runtime_error_200_div_by_0/www.merlyn.demon.co.uk/zel-1886.htm)
9. [Zeller's Algorithm: Day of the Week, Northern Illinois University](https://faculty.cs.niu.edu/~hutchins/csci297p2/webpages/zeller.htm)
10. [Hirofumi Nakai (2023). A Simple Formula for Doomsday. The Mathematical Intelligencer 45, 131–132.](https://link.springer.com/article/10.1007/s00283-022-10229-3)
11. [Lewis Carroll (1887). To Find the Day of the Week for Any Given Date. Nature 35, 517.](https://www.nature.com/articles/035517a0)
12. [Doomsday rule, Dictionary of Algorithms and Data Structures, NIST](https://xlinux.nist.gov/dads/HTML/doomsday.html)
13. [Methods for Accelerating Conway's Doomsday Algorithm (part 1), arXiv](https://arxiv.org/abs/1006.3913)
14. [ajcr/doomsday: Algorithms to compute the day of the week (Conway, Sakamoto, Zeller), GitHub](https://github.com/ajcr/doomsday)
15. [Calculating the day of the week: null-days algorithm, arXiv](https://arxiv.org/abs/1404.2510)
16. [Google Doodle Marks 434 Years of the Gregorian Calendar, TIME](https://time.com/4517862/google-doodle-gregorian-calendar-anniversary/)
17. [1752 Calendar Change, Connecticut State Library](https://libguides.ctstatelibrary.org/hg/colonialresearch/calendar)
18. [ISO 8601 — Date and time format, ISO](https://www.iso.org/iso-8601-date-and-time-format.html)

---
*Initially written Sep 17, 2026 · Reviewed: Oct 15, 2026 · Edited: Oct 15, 2026 · Last review: Oct 15, 2026*

Topic: 物质世界与数学 › 测量与时间 › 历法 › Calendar mechanics and reform › Calendrical calculation

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/determination-of-the-day-of-the-week

English original: https://www.edgepedia.org/determination-of-the-day-of-the-week
