我正在看一段代码,偶然发现使用timeIntervalBetween1970AndReferenceDate
和timeIntervalSinceReferenceDate
。
代码返回的时间戳以毫秒为单位:
return (Date.timeIntervalBetween1970AndReferenceDate + date.timeIntervalSinceReferenceDate) * 1000
这不等于:
return date.timeIntervalSince1970 * 1000
答案 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