10 月 25 日の始まりと終わりを比較すると、89999 秒 (25 時間) になります。
次の方法を使用して日付を比較します。
endOfDay.timeIntervalSinceDate(startOfDay)
ただし、時間を比較すると 24 になります。NSDate の次の拡張関数を使用して時間を比較します。
func differenceInHoursWith(date: NSDate) -> Int{
let components = NSCalendar.currentCalendar().components(.Hour, fromDate: self, toDate: date, options: [])
return components.hour
}
昼間の調整なしで秒単位で違いを得る方法はありますか? 私の場合、それらは必要なく、秒単位の粒度が必要です。