动态详情
This commit is contained in:
@@ -6,8 +6,7 @@
|
||||
//
|
||||
|
||||
#import "MonentsInfoModel.h"
|
||||
|
||||
#define aMinute 60
|
||||
#import "NSString+Utils.h"
|
||||
|
||||
@implementation MonentsInfoModel
|
||||
- (instancetype)init {
|
||||
@@ -23,62 +22,7 @@
|
||||
|
||||
|
||||
- (NSString *)publishTime {
|
||||
return [self stringWithTimeStamp:_publishTime];
|
||||
}
|
||||
|
||||
- (NSString *)stringWithTimeStamp:(NSString *)timeStamp {
|
||||
// 转为秒为单位
|
||||
NSTimeInterval second = timeStamp.longLongValue / 1000;
|
||||
NSDate *date = [NSDate dateWithTimeIntervalSince1970:second];
|
||||
|
||||
//把字符串转为NSdate
|
||||
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
|
||||
[dateFormatter setDateFormat:@"YYYY-MM-dd HH:mm:ss"];
|
||||
// 时间 10点10分
|
||||
NSDateFormatter *timeFormatter = [[NSDateFormatter alloc] init];
|
||||
[timeFormatter setDateFormat:@"HH:mm"];
|
||||
// 日期 2月18号
|
||||
NSDateFormatter *dayFormatter = [[NSDateFormatter alloc] init];
|
||||
[dayFormatter setDateFormat:@"MM月dd日"];
|
||||
// 日期 年月日
|
||||
NSDateFormatter *yearFormatter = [[NSDateFormatter alloc] init];
|
||||
[yearFormatter setDateFormat:@"YYYY年MM月dd日"];
|
||||
|
||||
//得到与当前时间差
|
||||
NSTimeInterval timeInterval = [date timeIntervalSinceNow];
|
||||
timeInterval = -timeInterval;
|
||||
|
||||
long temp = 0;
|
||||
NSString *result;
|
||||
|
||||
BOOL isSameDay = [[NSCalendar currentCalendar] isDateInToday:date]; // 是否是同一天
|
||||
|
||||
// A. 当天,且 timeInterval < 1分钟,显示“刚刚”;
|
||||
if (timeInterval < aMinute) {
|
||||
return [NSString stringWithFormat:@"刚刚"];
|
||||
|
||||
// B. 当天,且1分钟≤ timeInterval <60分钟,显示“n分钟前”;
|
||||
} else if((temp = timeInterval/aMinute) < 60){
|
||||
return [NSString stringWithFormat:@"%ld分钟前",temp];
|
||||
|
||||
// C. 当天,且n≥60分钟,显示“xx:xx”;
|
||||
} else if((temp = temp/60) < 24 && isSameDay){
|
||||
return [timeFormatter stringFromDate:date];
|
||||
|
||||
// C. 非当天,且n≥60分钟,显示“xx:xx”;
|
||||
} else if((temp = temp/60) < 24 && !isSameDay){
|
||||
return [dayFormatter stringFromDate:date];
|
||||
|
||||
// D. 跨天,且未跨年,显示“mm-dd”;
|
||||
} else if((temp = temp/30) < 30){
|
||||
return [dayFormatter stringFromDate:date];
|
||||
|
||||
} else {
|
||||
// E. 跨年,显示“yyyy-mm-dd”;
|
||||
return [yearFormatter stringFromDate:date];
|
||||
}
|
||||
|
||||
return result;
|
||||
return [NSString stringWithTimeStamp:_publishTime];
|
||||
}
|
||||
|
||||
@end
|
||||
|
Reference in New Issue
Block a user