Date and Time: how do I extract the hour and minutes from an NSDate

From IPhone Dev FAQ

Jump to: navigation, search

FelipeS> what's the quickest way to extract the time (hour and minutes) from an NSDate initialized with timeIntervalSince1970?

[11:47pm] <dang`r`us> FelipeS, NSDateComponents

[11:48pm] <dang`r`us> unsigned unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit; NSDateComponents *comps = [[NSCalendar currentCalendar] components:unitFlags fromDate:yourDate]; // then, comps.day etc

[11:48pm] <FelipeS> ah, great. thanks

[11:48pm] <dang`r`us> different flags though

Personal tools