NSCalendar *calendar = [NSCalendar currentCalendar];
unsigned unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit;
NSDateComponents *components = [calendar components:unitFlags fromDate:[NSDate date]];
NSInteger iCurYear = [components year]; //当前的年份
NSInteger iCurMonth = [components month]; //当前的月份
NSString *iStr = [NSString stringWithFormat:@"%02d",iCurMonth];
NSInteger iCurDay = [components day]; // 当前的号数
calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSRange range = [calendar rangeOfUnit:NSDayCalendarUnit inUnit:NSMonthCalendarUnit forDate:[NSDate date]];
NSUInteger numberOfDaysInMonth = range.length;
时间: 2024-10-27 18:56:02