Retrieving 1st day of month using NSCalendar
-
29-10-2019 - |
سؤال
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.
لا يوجد حل صحيح
لا تنتمي إلى StackOverflow