//返回時(shí)間格式
NSCalendar? *calendar = [NSCalendar currentCalendar];
//1.獲取當(dāng)前的時(shí)間
NSDate *currentDate = [NSDate date];
// 獲取年窗轩,月,日
NSDateComponents *components = [calendar components:NSCalendarUnitYear|NSCalendarUnitMonth|NSCalendarUnitDay fromDate:currentDate];
NSInteger currentYear = components.year;
NSInteger currentMonth = components.month;
NSInteger currentDay = components.day;
//2.獲取消息發(fā)送時(shí)間
NSDate *msgDate = [NSDate dateWithTimeIntervalSince1970:timestamp/1000.0];
// 獲取年,月冰蘑,日
components = [calendar components:NSCalendarUnitYear|NSCalendarUnitMonth|NSCalendarUnitDay fromDate:msgDate];
CGFloat msgYead = components.year;
CGFloat msgMonth = components.month;
CGFloat msgDay = components.day;
//3.判斷:
/*今天:(HH:mm)
*昨天: (昨天 HH:mm)
*昨天以前:(2015-09-26 15:27)
*/
NSDateFormatter *dateFmt = [[NSDateFormatter alloc] init];
if (currentYear == msgYead&& currentMonth == msgMonth&& currentDay == msgDay) {//今天?
dateFmt.dateFormat= @"hh:mm";
}else if(currentYear == msgYead&& currentMonth == msgMonth&& currentDay - 1 == msgDay){//昨天
dateFmt.dateFormat= @"昨天 hh:mm";
}else{//昨天以前
dateFmt.dateFormat= @"yyy-MM-dd hh:mm";
}