Swift 时间
timeInterval 指的是两个时间间隔的秒数.比如
let now = Date().timeIntervalSince1970 // 从1970距今的秒数
这个返回的即时unix时间戳
自定义时间
// 一天是86400秒
let yestoday = Date(timeIntervalSinceNow:-86400).timeIntervalSince1970
时间比较
func compareDate(_ dateA: Date, withAnotherDate dateB: Date) {
let result = dateA.compare(dateB)
if result == ComparisonResult.orderedAscending {
print("now compared with feture")
} else if result == ComparisonResult.orderedDescending {
print("now compared with past")
} else {
print("I think you compared with yourself")
}
}
本文由 创作,采用 知识共享署名4.0 国际许可协议进行许可。本站文章除注明转载/出处外,均为本站原创或翻译,转载前请务必署名。最后编辑时间为: 2021/05/26 07:58