views:

509

answers:

1

Hi all,

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?

Thanx in advance.

+1  A: 

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
It's giving me an error : 'gregorian' undeclared (first use in this function)
neha
Replace gregorian by [NSCalendar currentCalendar]
JeremyP
Thanks, edited into answer.
Paul Lynch