是timeIntervalBetween1970AndReferenceDate + timeIntervalSinceReferenceDate = timeIntervalSince1970

时间:2018-06-29 18:13:37

标签: swift date

我正在看一段代码,偶然发现使用timeIntervalBetween1970AndReferenceDatetimeIntervalSinceReferenceDate

代码返回的时间戳以毫秒为单位:

return (Date.timeIntervalBetween1970AndReferenceDate + date.timeIntervalSinceReferenceDate) * 1000

这不等于:

return date.timeIntervalSince1970 * 1000

1 个答案:

答案 0 :(得分:0)

确实,没有区别。 setup_databases具有类型属性

Date

和实例属性

public static let timeIntervalBetween1970AndReferenceDate: TimeInterval
// The number of seconds from 1 January 1970 to the reference date, 1 January 2001

这意味着对于类型为public var timeIntervalSinceReferenceDate: TimeInterval { get } // The interval between the date value and 00:00:00 UTC on 1 January 2001. public var timeIntervalSince1970: TimeInterval { get } // The interval between the date value and 00:00:00 UTC on 1 January 1970. 的任何值date来说,身份都是

Date

按住。实际上,正如我们在Date.swift#L111中看到的那样,Date.timeIntervalBetween1970AndReferenceDate + date.timeIntervalSinceReferenceDate == date.timeIntervalSince1970 的实现方式为

timeIntervalSince1970