英文:
Why is it not possible to represent some of the dates in nanoseconds?
问题
我想将一个日期转换为自 Unix 纪元以来的纳秒数。但它有一个限制,即对于 1678 年之前或 2262 年之后的日期,它具有未定义的行为。这是什么原因呢?
英文:
I wanted to convert a date into nanoseconds since unix epoch.But it has the limitation that it has undefined behavior for dates before 1678 or after 2262. What is the reason for that?
答案1
得分: 2
只是回答问题:
((2^64) / (10^9)) / (60 * 60 *24 * 365.25) ~= 584.5 年
1678 + 584 = 2262
所以是的,选择的日期范围是因为这是 int64 的范围。
由于 584 / 2 = 292,1678 + 292 = 1970,我怀疑 0(旧的纪元日期:1970/01/01)是新范围的中间值。这是有道理的,因为这意味着可以通过将整数值乘以/除以10的幂来改变精度。
英文:
Just to answer the question:
((2^64) / (10^9)) / (60 * 60 *24 * 365.25) ~= 584.5 years
1678 + 584 = 2262
So yes, the date range chosen is because that is the range of an int64.
Since 584 / 2 = 292 and 1678 + 292 = 1970, I suspect that 0 (the old epoch date: 1970/01/01) is the middle the new range. That would make sense as it means it is possible to change precision just by multiplying / dividing the integer value by powers of 10
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论