+ (NSString *)stringWithDate:(NSDate *)date{ // 1.获得年月日 NSCalendar *calendar = [NSCalendar currentCalendar]; NSUInteger unitFlags = NSCalendarUnitYear| NSCalendarUnitMonth | NSCalendarUnitDay |NSCalendarUnitHour |NSCalendarUnitMinute; NSDateComponents *cmp1 = [calendar components:unitFlags fromDate:date]; NSDateComponents *cmp2 = [calendar components:unitFlags fromDate:[NSDate date]]; // 2.格式化日期 NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; if (cmp1.year == cmp2.year) { if (cmp1.month == cmp2.month) { NSInteger delta_day = cmp1.day - cmp2.day; switch (delta_day) { case : { formatter.dateFormat = @"今天 HH:mm"; }