Thursday, June 9, 2011

How to get the Date Components from NSDate in Objective-C ?



NSDate *date = [NSDate date];
NSDateComponents *dateComponents = [[NSCalendar currentCalendar] components:NSDayCalendarUnit fromDate:date];
NSInteger _day=[dateComponents day];

dateComponents = [[NSCalendar currentCalendarcomponents:NSMonthCalendarUnit fromDate:date];
NSInteger _month=[dateComponents month];








Similarly, you can get the other components like year, hour, seconds etc , you will have to change components: to relevant CalendarUnit and you can access them with [dateComponents year], [dateComponents hour] etc.

1 comment:


  1. nice blogs.
    Friend chatMake new friend’s without revealing yourself. Dial 543216 at Rs 2/min and monthly subscription of Rs 30/ 30 days.

    ReplyDelete