【发布时间】:2018-02-17 06:05:49
【问题描述】:
我试图找出 2 个日期之间的差异。它返回几天的无效值。即使它以秒为单位返回错误的差异,也会导致无效的天数。
(lldb) po earliest
▿ 2038-01-16 22:42:52 +0000
- timeIntervalSinceReferenceDate : 1168987372.695472
(lldb) po self
▿ 2038-02-16 22:42:52 +0000
- timeIntervalSinceReferenceDate : 1171665772.695472
(lldb) po Calendar.current.dateComponents([.second], from: earliest, to: self)
▿ second: 2678399 isLeapMonth: false
- second : 2678399
- isLeapMonth : false
以秒为单位的差异应该是2678400,我在一些在线日期差异网站上检查过这个。不知道为什么会发生这个奇怪的问题。
【问题讨论】:
-
Calendar.current.dateComponents([.day], from: early, to: date).day 显示 30,这是正确的。你期望什么价值?
-
您需要将 timeIntervalSinceReferenceDate 打印到更多小数位,以说明您获得结果的原因。