If anyone needs to work with NSDate
, here's a snippet that specifies a format and reads dates from a plist. It also finds the seconds / interval between each date and the startDate.
override func setup() {
let df = NSDateFormatter()
df.dateFormat = "MMM d, y, hh:mm:ss a"//Apr 11, 2016, 10:00:00 AM
if let path = NSBundle.mainBundle().pathForResource("date", ofType: "plist") {
if let array = NSArray(contentsOfFile: path) as? [NSDate] {
let startDate = array[0]
let eventDate = array[1]
let ti = eventDate.timeIntervalSinceDate(startDate)
print(ti)
print(ti/3600.0)
}
}
}
}