IOS gets the number of days of the month for a specified month _ios

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.