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?
Asked
Active
Viewed 1.1k times
1 Answers
16
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];

Paul Lynch
- 19,769
- 4
- 37
- 41
-
It's giving me an error : 'gregorian' undeclared (first use in this function) – neha May 12 '10 at 11:29
-
Replace gregorian by [NSCalendar currentCalendar] – JeremyP May 12 '10 at 12:11