【发布时间】:2015-05-13 18:51:47
【问题描述】:
除了函数的输入和输出,NSDate的有什么区别
func timeIntervalSinceDate(anotherDate: NSDate) -> NSTimeInterval
和NSCalendar的
func components(unitFlags: NSCalendarUnit, fromDate startingDate: NSDate, toDate resultDate: NSDate, options opts: NSCalendarOptions) -> NSDateComponents
?
哪个函数更精确?哪些函数会考虑夏令时、闰秒等?
例如:
let today = NSDate()
let someDate = RandomFutureDate() // Assumes this gives random future date
let seconds = futureDate.timeIntervalSinceDate(today)
let anotherSeconds = NSCalendar.currentCalendar().components(.CalendarUnitSecond, fromDate: today, toDate: futureDate, options: nil).second
seconds 或 anotherSeconds 哪个更准确/正确?
注意:seconds 可能看起来更准确,因为它是双精度数,但它是否考虑了 DST、闰秒等?
【问题讨论】:
标签: ios swift nsdate nscalendar nstimeinterval