neha
neha

Reputation: 6377

Converting UNIX timestamp into date, hours, minutes, seconds

How can you convert the UNIX timestamp (that is in the form of a number denoting timestamp) into date, time(hours, minutes, seconds) in Objective-C?

Upvotes: 12

Views: 11226

Answers (1)

Paul Lynch
Paul Lynch

Reputation: 19789

For output, use an NSDateFormatter. To extract values for other purposes, use NSDateComponents. eg:

NSDate *date = [NSDate dateWithTimeIntervalSince1970:1234567];
NSDateComponents *weekdayComponents = [[NSCalendar currentCalendar] components:NSWeekdayCalendarUnit fromDate:date];
int weekday = [weekdayComponents weekday];

Upvotes: 16

Related Questions