/** 是否为今年 */ - (BOOL)isThisYear { if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) { NSCalendar *calendar = [NSCalendar currentCalendar]; NSInteger nowYear = [calendar component:NSCalendarUnitYear fromDate:[NSDate date]]; NSInteger selfYear = [calendar component:NSCalendarUnitYear fromDate:self]; return nowYear == selfYear; } NSDate *now = [NSDate date]; NSCalendar *calendar = [NSCalendar currentCalendar]; NSUInteger unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit; NSDateComponents *dateComponent = [calendar components:unitFlags fromDate:now]; int year = [dateComponent year]; if (year) { return YES; } return NO; }
时间: 2024-11-13 06:36:12