converting timestamp to nsdate format

ramya picture ramya · Jun 20, 2011 · Viewed 55.9k times · Source

I want to convert my timestamp value 1308031456 to NSDate format (which yields the value Tue, 14 Jun 2011 06:04:16 GMT in online web conversion). How would I convert between the two programmatically?

Answer

KingofBliss picture KingofBliss · Jun 20, 2011

OBJ - C: Use dateWithTimeIntervalSince1970:,

NSDate *date = [NSDate dateWithTimeIntervalSince1970:timeStamp];

SWIFT: Use init(timeIntervalSince1970:)

let date = NSDate(timeIntervalSince1970:timeStamp)