I have been researching, but I couldnt find exact solution for my problem. I have been trying to get 1 hour ago from a date. How can I achieve this in swift?
Please read the NSDate class reference.
NSDate
let oneHourAgo = NSDate.dateWithTimeIntervalSinceNow(-3600)
should do it.
Or, for any NSDate object:
let oneHourBack = myDate.dateByAddingTimeInterval(-3600)
Swift 4:
let oneHourAgo = NSDate(timeIntervalSinceNow: -3600)