Objective
This function is often used in developing iOS, and the one-month interval is the first and last day, and you need to know how many days of the month to know what the last day is, and whether it is a leap year, maybe 28 days in February.
Not much to say, 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 in a month-(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% = = 0) return 29;
if (year% = = 0) return 28;
return 29; }
Summarize
The above is the full content of iOS to get the number of days of the month, I hope the content of this article will help you develop iOS.