问题描述
我刚刚在运行日历脚本时发现,PHP 中的时间戳限制为 2038.这到底是什么意思?为什么是 2038 而不是 2050 或 2039?如果时间戳只计算给定日期(1970 年)的秒数,为什么要限制?
I just found out, running a calendar script, that timestamps in PHP has a limit to 2038. What does it really mean? Why is it 2038 instead of 2050 or 2039? Why a limit if timestamps just count seconds from a given date (1970)?
推荐答案
限制是由大多数 C 库用于表示该计数的 4 字节有符号整数强加的.快速数学(假设 365 天年,不完全正确):
The limit is imposed by the 4 byte signed integers that most C libraries use for representing that count. Quick math (assumes 365 day years, not exactly correct):
2147483648 seconds ~ 68.1 years
这也意味着下限约为 1900.一些库已经开始引入 64 位 epoch 计数,但目前还很少.
This also implies a lower limit of ~1900. Some libraries have started to introduce 64 bit epoch counts, but they are few and far between for the moment.
这篇关于为什么时间戳限制为 2038?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!