gpt4 book ai didi

swift - 是 timeIntervalBetween1970AndReferenceDate + timeIntervalSinceReferenceDate = timeIntervalSince1970

转载 作者:行者123 更新时间:2023-11-30 11:22:45 29 4
gpt4 key购买 nike

我正在查看代码并偶然发现了 timeIntervalBetween1970AndReferenceDatetimeIntervalSinceReferenceDate 的使用。

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

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

这不是相当于:

return date.timeIntervalSince1970 * 1000

最佳答案

确实,没有什么区别。 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.timeIntervalBetween1970AndReferenceDate + date.timeIntervalSinceReferenceDate
== date.timeIntervalSince1970

成立。事实上,正如我们在 Date.swift#L111 中看到的那样, timeIntervalSince1970 实现为

public var timeIntervalSince1970: TimeInterval {
return self.timeIntervalSinceReferenceDate + Date.timeIntervalBetween1970AndReferenceDate
}

关于swift - 是 timeIntervalBetween1970AndReferenceDate + timeIntervalSinceReferenceDate = timeIntervalSince1970,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51107324/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com