1. 程式人生 > >ios 獲取某年某月總共多少天

ios 獲取某年某月總共多少天

// 獲取某年某月總共多少天
- (int)getDaysInMonth:(int)year month:(int)imonth {
    // imonth == 0的情況是應對在CourseViewController裡month-1的情況
    if((imonth == 0)||(imonth == 1)||(imonth == 3)||(imonth == 5)||(imonth == 7)||(imonth == 8)||(imonth == 10)||(imonth == 12))
        return 31;
    if((imonth == 4)||(imonth == 6)||(imonth == 9
)||(imonth == 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; }