1、yyyy-MM-dd-> 今天、昨天、MM月dd日,注意dateFormater的格式一定要对应上传参过来的日期格式
+ (NSString *)dateToTitleDateString:(NSString *)dateString {
NSDateFormatter *dateFormater = [NSDateFormatter new];
dateFormater.dateFormat = @"yyyy-MM-dd";
NSDate *today = [NSDate date];
NSDate *yesterday = [NSDate dateWithTimeIntervalSinceNow:-(24*60*60)];
NSString *todayString = [dateFormater stringFromDate:today];//今天
NSString *yestoday = [dateFormater stringFromDate:yesterday];//昨天
NSString *titleDateString = @"今天";
if ([dateString isEqualToString:todayString]) {
titleDateString = @"今天";
}else if ([dateString isEqualToString:yestoday]){
titleDateString = @"昨天";
}else {
NSDate *tempDate = [dateFormater dateFromString:dateString];
dateFormater.dateFormat = @"MM月dd日";
titleDateString = [dateFormater stringFromDate:tempDate];
}
return titleDateString;
}
网友评论