/**
* 设置 天数
*/
- (void)setTimesLabelWithTime:(NSString*)strTime
{
//计算
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"YYYY-MM-dd HH:mm:ss"];
NSDate *datePKTime = [formatter dateFromString:strTime];
NSDate *dateNow = [NSDate date];
NSString *strToday = [formatter stringFromDate:[NSDate date]];
NSInteger dayN = ([dateNow timeIntervalSince1970] - [datePKTime timeIntervalSince1970])/(3600*24);
BOOL today = [[strTime substringToIndex:10] isEqualToString:[strToday substringToIndex:10]];
if (today) {
[_timeLabel setText:@"今天"];
} else {
if (dayN <= 1) {
[_timeLabel setText:@"1天前"];
} else if (dayN >1 && dayN <= 7) {
[_timeLabel setText:[NSString stringWithFormat:@"%tu天前",dayN]];
} else {
BOOL thisYear = [[strTime substringToIndex:4] isEqualToString:[strToday substringToIndex:4]];
if (thisYear) {
[_timeLabel setText:[strTime substringWithRange:NSMakeRange(5, 5)]];
}else {
[_timeLabel setText:[strTime substringToIndex:10]];
}
}
}
}