91 lines
2.3 KiB
Objective-C
91 lines
2.3 KiB
Objective-C
//
|
||
// MonentsInfoModel.m
|
||
// xplan-ios
|
||
//
|
||
// Created by 冯硕 on 2022/5/11.
|
||
//
|
||
|
||
#import "MonentsInfoModel.h"
|
||
|
||
#define aMinute 60
|
||
|
||
@implementation MonentsInfoModel
|
||
- (instancetype)init {
|
||
if (self = [super init]) {
|
||
self.isFold = YES;
|
||
}
|
||
return self;
|
||
}
|
||
|
||
+ (NSDictionary *)objectClassInArray {
|
||
return @{@"dynamicResList":MonentsPicInfoModel.class};
|
||
}
|
||
|
||
|
||
- (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;
|
||
}
|
||
|
||
@end
|
||
|
||
|
||
@implementation MonentsPicInfoModel
|
||
|
||
|
||
@end
|