In a one-month interval for the first and last day, you need to know how many days of the month you have to know what the last day is, and whether it is a leap year, maybe 28 days in February.
Attached code:
-(void) Viewdidload {
[Super Viewdidload];
Do no additional setup after loading the view, typically from a nib.
NSLog (@ "%ld", (long) [self howmanydaysinthisyear:2016 withmonth:1]);
NSLog (@ "%ld", (long) [self howmanydaysinthisyear:2016 withmonth:2]);
NSLog (@ "%ld", (long) [self howmanydaysinthisyear:2016 withmonth:3]);
NSLog (@ "%ld", (long) [self howmanydaysinthisyear:2016 withmonth:4]);
NSLog (@ "%ld", (long) [self howmanydaysinthisyear:2016 withmonth:5]);
NSLog (@ "%ld", (long) [self howmanydaysinthisyear:2016 withmonth:6]);
NSLog (@ "%ld", (long) [self howmanydaysinthisyear:2016 withmonth:7]);
NSLog (@ "%ld", (long) [self howmanydaysinthisyear:2016 withmonth:8]);
}
#pragma mark-Get the number of days of the month of a year
-(Nsinteger) Howmanydaysinthisyear: (Nsinteger) Year Withmonth: (Nsinteger) month{
if ((month = 1) | | (month = 3) | | (month = 5) | | (month = 7) | | (month = 8) | | (month = 10) | | (month = 12))
return 31;
if ((month = 4) | | (month = 6) | | (month = 9) | | (month = 11))
return 30;
if (year% 4 = 1) | | (Year% 4 = 2) | | (Year% 4 = 3))
{
return 28;
}
If (year% 400 = 0)
return 29;
if (year% 100 = 0)
return 28;
return 29;
}