tags:

views:

190

answers:

1

Hi. Is there any way/ method to seperate month & year form NSDate?

I just need to display current month & year? Any Example?

+1  A: 

This could be done by using NSDateComponents

Espo
Thanks Espo. I got the Solution :
Nic
NSDateFormatter *dateformatter = [[NSDateFormatter alloc] init];
Nic
[dateformatter setDateFormat:@"MM/dd/yyyy hh:mm a"];
Nic
NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
Nic
NSDateComponents *currentDateComponents = [gregorian components:( NSWeekdayCalendarUnit | NSYearCalendarUnit | NSMonthCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSWeekCalendarUnit) fromDate:current_date];
Nic
NSLog(@"- current components year = %i , month = %i , week = % i, weekday = %i", [currentDateComponents year], [currentDateComponents month], [currentDateComponents week], [currentDateComponents weekday]);
Nic