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.
Add
after initializing your NSCalendar.
[NSDate date]will return a date in the UTC timezone, well an absolute interval since January 1, 2001 00:00 GMT, but the NSCalendar has its timeZone set to the default timezone which may not be UTC.UTC is the “same” as UTC, a quote from wikipedia: