# 2038年问题

2038年问题（也写作Y2038、Y2K38或“纪元末日”）是一种整数溢出问题，将影响那些用有符号32位整数存储Unix时间的计算机系统。Unix时间是指自1970年1月1日00:00:00 UTC起经过的秒数。这种计数器能容纳的最后一个值是2,147,483,647，在2038年1月19日03:14:07 UTC到达；一秒之后，补码（一种二进制表示方案，符号位翻转即产生负值）值回绕为−2,147,483,648，将其解释为Unix时间的系统会把它读作1901年12月13日20:45:52 UTC。<sup>[1](https://y2038problem.com/what-is-y2038.html)</sup>

| 关键事实 | 详情 |
|---|---|
| 最后一个有效秒 | 2038-01-19 03:14:07 UTC，此时有符号32位计数器达到2,147,483,647<sup>[1](https://y2038problem.com/what-is-y2038.html)</sup> |
| 回绕后的解释 | 1901-12-13 20:45:52 UTC，向后跳了136年<sup>[1](https://y2038problem.com/what-is-y2038.html)</sup> |
| 无符号变通方案 | 无符号32位计数器将上限延至2106-02-07 06:28:15 UTC<sup>[1](https://y2038problem.com/what-is-y2038.html)</sup> |
| 64位范围 | 有符号64位计数器可达到公元292,277,026,596年<sup>[1](https://y2038problem.com/what-is-y2038.html)</sup> |
| 最早记录的故障 | AOLserver，2006年5月13日，一个十亿秒的超时提前31年溢出了32位时间<sup>[2](https://y2038problem.com/timeline.html)</sup> |
| Linux修复 | 内核5.6（2020年）在32位架构上增加了64位时间支持；glibc 2.34通过`_TIME_BITS=64`将其暴露出来<sup>[3](https://y2038problem.com/linux.html)</sup> |
| 标准变更 | POSIX.1-2024要求`time_t`至少为64位宽<sup>[4](https://www.man7.org/linux/man-pages/man3/time_t.3type.html)</sup> |

## 算术原理

Unix时间计算自Unix纪元——1970年1月1日00:00:00 UTC——起经过的秒数。有符号32位整数可容纳从−2,147,483,648到2,147,483,647的值，因此可表示的范围从1901年12月13日到2038年1月19日。在溢出的那一秒，符号位翻转，将该结果视为时间戳的代码读到的日期是纪元之前68年，而不是最后一个有效值之后一秒。<sup>[1](https://y2038problem.com/what-is-y2038.html)</sup>

这个问题在成因和修复方式上都与千年虫问题不同。千年虫是十进制编码问题，年份用两位数字表示；Y2038是二进制宽度问题，31个数值位加一个符号位。对于32位`time_t`，不存在窗口化技巧：任何重新解释都会破坏1970年之前的日期，或者破坏每个传递时间值的库的应用二进制接口。<sup>[1](https://y2038problem.com/what-is-y2038.html)</sup>

## 2038年之前的故障

溢出不会等到2038年。任何将时长加到当前时间并将结果存入32位的代码，只要和超过上限就会溢出。最早被广泛记录的案例是2006年5月13日的AOLserver Web服务器：一个设为十亿秒之后的超时落在了32位上限之外，到期日变成了过去的日期，服务随即崩溃。<sup>[2](https://y2038problem.com/timeline.html)</sup>养老金计算器、租赁系统、证书生成器和长期维护计划，只要向前看得足够远，都会撞上同一堵墙。<sup>[1](https://y2038problem.com/what-is-y2038.html)</sup>

国家计算博物馆的修复人员在2025年修复一台使用1982年C编译器的DEC PDP-11/73时，发现了另一个例证：当系统时钟向前拨动时，调用时间函数的程序在2037年初就崩溃了——比主要回绕点早了一年——而本地时间函数返回的是1970年，而不是预期的1901年。<sup>[5](https://www.theregister.com/software/2025/08/23/the-unix-epochalypse-might-be-sooner-than-you-think/1378860)</sup>

## 风险仍然存在的地方

**桌面与服务器系统**大体上是安全的。面向64位硬件的操作系统，包括Linux、Windows、macOS、iOS和Android，使用64位有符号`time_t`，不存在系统性的Y2038问题。<sup>[6](https://y2038.com/y2038-readiness-update-whats-ready-and-what-isnt-in-2025/)</sup>然而，64位系统仍可能运行不合规的32位软件，而且即使在64位机器上，问题也可能持续存在于应用程序、设备驱动、数据库、存储系统和网络协议中。<sup>[7](https://y2038.com/faq/)</sup>

**32位硬件上的Linux**分阶段获得了受支持的解决路径。2020年发布的内核5.6通过新的time64系统调用在32位架构上增加了64位时间支持，使嵌入式板卡不至于被困死。<sup>[3](https://y2038problem.com/linux.html)</sup>从glibc 2.34起，32位程序可以通过同时定义`_TIME_BITS 64`和`_FILE_OFFSET_BITS 64`来请求64位时间；对于任何将`time_t`放入公开结构体的库来说，这都是一次应用二进制接口变更，因此各发行版必须重新构建受影响的软件包。<sup>[3](https://y2038problem.com/linux.html)</sup>Debian在其13版本（trixie）中完成了这一过渡：除i386之外的所有架构现在都使用64位`time_t`应用二进制接口，支持2038年之后的日期；而i386仍停留在32位时间，因为它的职责是运行遗留的x86二进制文件。<sup>[8](https://www.debian.org/News/2025/20250809)</sup>在armel和armhf上，许多库的应用二进制接口发生了变化却没有提升soname，因此处理日期的第三方程序必须重新编译。<sup>[9](https://www.debian.org/releases/trixie/release-notes.es.pdf)</sup>GNU Gnulib的`year2038`模块为软件构建自动化了其中一部分工作，在运行glibc 2.34及以上的32位Linux系统上安排以`_TIME_BITS=64`进行编译。<sup>[10](https://www.gnu.org/software/gnulib/manual/html_node/Avoiding-the-year-2038-problem.html)</sup>

**其他操作系统**通过不同途径更早地解决了问题。NetBSD在NetBSD 5到NetBSD 6之间将`time_t`从32位改为64位，使用符号重命名，使旧的32位原型二进制文件能够与新的64位二进制文件并行运行。<sup>[11](https://wiki.netbsd.org/symbol_versions/)</sup>在Windows上，Microsoft C运行库提供`_gmtime32`，它只表示到2038年1月18日23:59:59 UTC为止的日期，以及`_gmtime64`，可到达3000年12月31日；除非定义了`_USE_32BIT_TIME_T`，否则`time_t`映射为64位类型，而微软不建议使用该设置，在64位平台上也不允许使用。<sup>[12](https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/gmtime-gmtime32-gmtime64?view=msvc-160)</sup>

**磁盘格式与传输格式**独立于操作系统携带这一限制。Unix系统使用的TZif时区格式将版本1的转换时间存储为32位值，限于1901-12-13 20:45:52至2038-01-19 03:14:07 UT，版本2和3则扩展至64位值。<sup>[13](https://datatracker.ietf.org/doc/rfc8536/)</sup>MySQL的`TIMESTAMP`类型在所有平台上最大值为'2038-01-19 03:14:07.999999' UTC，更晚的日期建议使用`DATETIME`。<sup>[14](https://downloads.mysql.com/docs/mysql-8.0-relnotes-en.a4.pdf)</sup>文件系统各不相同：ext4将时间戳存储在34位字段中，范围可达2446年；而没有`bigtime`特性的XFS以及较早的FAT系列格式仍然受限，后者将年份存储为相对于1980年的7位值，只能到达2107年。<sup>[15](https://epochkit.dev/blog/year-2038-problem)</sup><sup> • </sup><sup>[16](https://learn.microsoft.com/en-US/windows/win32/fileio/exfat-specification)</sup>

**嵌入式与工业系统**是最困难的一类。可编程逻辑控制器、仪表、发动机控制单元或成像设备中的32位片上系统，到2038年可能仍安装在役，因为当初的采购规格就是如此；服务寿命以十年计，更新渠道缓慢且有时因合同而冻结，而使用未来日期的功能——如日志记录、证书检查和计划维护——恰恰是会失效的那些。<sup>[17](https://y2038problem.com/embedded)</sup>每年仍有数十亿台32位嵌入式设备出货，32位微控制器单元的销量不降反升。<sup>[6](https://y2038.com/y2038-readiness-update-whats-ready-and-what-isnt-in-2025/)</sup>实时操作系统厂商已经作出回应：VxWorks 7自2020年起支持64位时间戳，Wind River于2025年为VxWorks 6.9.4.12发布了更新，为关键组件增加了2038年支持。<sup>[18](https://www.windriver.com/blog/Back-to-the-Future-and-the-Year-2038-Problem-Keeping-Embedded-Systems-on-Track)</sup>

## 邻近的回绕点

Unix Y2038是落在同一个两年区间内的若干计时不连续点之一，每个都有不同的表示方式。网络时间协议的32位秒字段自1900年起计数，在2036年2月7日NTP第1纪元开始时回绕。<sup>[19](https://datatracker.ietf.org/doc/rfc5905/)</sup>DVB-SI的16位简化儒略日于2038年4月23日回绕，遗留GPS的10位周数于2038年11月20日回绕。<sup>[20](https://y2038problem.com/)</sup>标准机构已开始协调：ITU-T第17研究组于2026年6月10日同意了一个工作项XSTP.epoch，旨在编写一份关于2038类回绕事件（包括2036、2038和2106年）全球协调需求的技术文件，研究在可用时间表内无法实现完全补救时的发现、清点、测试和危害最小化策略。<sup>[21](https://www.itu.int/Itu-t/workprog/wp_item.aspx?isn=23741)</sup>

## 缓解措施

标准的修复方法是使用更宽的整数。POSIX.1-2024现在要求`time_t`至少为64位宽，尽管一些系统仍默认为32位，而且在某些架构上可以通过`_TIME_BITS`特性测试宏控制宽度。<sup>[4](https://www.man7.org/linux/man-pages/man3/time_t.3type.html)</sup>有符号64位计数器大约2920亿年都不会溢出。<sup>[1](https://y2038problem.com/what-is-y2038.html)</sup>对于无法更改类型的代码，将有符号32位时间戳经由无符号32位值转换为64位`time_t`——正如MIT Kerberos文档为其`krb5_timestamp`类型所规定的那样——可在具有64位`time_t`的平台上将覆盖范围延至2106年2月。<sup>[22](https://web.mit.edu/kerberos/www/krb5-latest/doc/appdev/y2038.html)</sup>用无符号类型替换有符号32位类型是同一思路的更廉价变体，以无法表示1970年之前的日期为代价，多买到68年。<sup>[7](https://y2038.com/faq/)</sup>

## References

1. [What is the Year 2038 problem? Y2038 Problem reference site](https://y2038problem.com/what-is-y2038.html)
2. [Y2038 timeline: incidents, fixes and neighbouring rollovers](https://y2038problem.com/timeline.html)
3. [Y2038 and Linux: kernel 5.6, glibc time64, Debian Trixie](https://y2038problem.com/linux.html)
4. [time_t(3type), Linux man-pages project](https://www.man7.org/linux/man-pages/man3/time_t.3type.html)
5. [The Unix Epochalypse might be sooner than you think, The Register (23 August 2025)](https://www.theregister.com/software/2025/08/23/the-unix-epochalypse-might-be-sooner-than-you-think/1378860)
6. [Y2038 Readiness Update: What's Ready and What Isn't in 2025, Y2038.com](https://y2038.com/y2038-readiness-update-whats-ready-and-what-isnt-in-2025/)
7. [FAQ, Y2038.com](https://y2038.com/faq/)
8. [Debian 13 "trixie" released, Debian News (9 August 2025)](https://www.debian.org/News/2025/20250809)
9. [Release Notes for Debian 13 (trixie), Debian Documentation Project](https://www.debian.org/releases/trixie/release-notes.es.pdf)
10. [Avoiding the year 2038 problem, GNU Gnulib manual](https://www.gnu.org/software/gnulib/manual/html_node/Avoiding-the-year-2038-problem.html)
11. [Symbol Versions in NetBSD Libraries, NetBSD Wiki](https://wiki.netbsd.org/symbol_versions/)
12. [gmtime, _gmtime32, _gmtime64, Microsoft Learn](https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/gmtime-gmtime32-gmtime64?view=msvc-160)
13. [RFC 8536: The Time Zone Information Format (TZif), IETF](https://datatracker.ietf.org/doc/rfc8536/)
14. [MySQL 8.0 Release Notes, Oracle](https://downloads.mysql.com/docs/mysql-8.0-relnotes-en.a4.pdf)
15. [The year 2038 problem: what breaks on January 19, 2038 and why, Epochkit](https://epochkit.dev/blog/year-2038-problem)
16. [exFAT File System Specification, Microsoft Learn](https://learn.microsoft.com/en-US/windows/win32/fileio/exfat-specification)
17. [Y2038 in embedded and industrial systems](https://y2038problem.com/embedded)
18. [Back to the Future and the Year 2038 Problem: Keeping Embedded Systems on Track, Wind River blog](https://www.windriver.com/blog/Back-to-the-Future-and-the-Year-2038-Problem-Keeping-Embedded-Systems-on-Track)
19. [RFC 5905: Network Time Protocol Version 4, IETF](https://datatracker.ietf.org/doc/rfc5905/)
20. [Year 2038 problem: countdown, systems still at risk](https://y2038problem.com/)
21. [ITU-T Work Programme item XSTP.epoch, SG17 Q4/17](https://www.itu.int/Itu-t/workprog/wp_item.aspx?isn=23741)
22. [Year 2038 considerations for uses of krb5_timestamp, MIT Kerberos Documentation](https://web.mit.edu/kerberos/www/krb5-latest/doc/appdev/y2038.html)

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

Topic: 物质世界与数学 › 数学与统计学 › 数与代数 › Arithmetic and number systems › Computational arithmetic › Integer overflow, underflow, and wraparound

Copyright 2026 Edgepedia

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

Source: https://www.edgepedia.org/zh/year-2038-problem

English original: https://www.edgepedia.org/year-2038-problem
