Swift 时间

2017-04-03  本文已影响22人  JaiUnChat

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")
    }

}
上一篇 下一篇

猜你喜欢

热点阅读