对于涉及NSDate的正确计算,要考虑到不同日历的所有极端情况(例如,在夏令时之间进行切换),应使用NSCalendar类:
迅捷3+
let earlyDate = Calendar.current.date( byAdding: .hour, value: -1, to: Date())
较旧
// Get the date that was 1hr before nowlet earlyDate = NSCalendar.currentCalendar().dateByAddingUnit( .Hour, value: -1, toDate: NSDate(), options: [])



