Retrieving 1st day of month using NSCalendar

I execute following snippet of code:

NSCalendar *gregorian = [[NSCalendar alloc]initWithCalendarIdentifier:NSGregorianCalendar];
NSDateComponents *comp = [gregorian components:(NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit) fromDate:[NSDate date]]; 
[comp setDay:1]; 

NSDate *firstDayOfMonthDate = [gregorian dateFromComponents:comp];

The Value of firstDayOfMonthDate is = 30-4-2011 but excpeted is 1-5-2011 i.e I want first date of month of any specified date. But it gives me the last date of the previous month.

thanks in advance.

5
задан tamasgal 7 May 2011 в 11:05
поделиться