Files
yinmeng-ios/xplan-ios/Main/Monents/Model/MonentsInfoModel.m
2022-08-26 21:38:47 +08:00

91 lines
2.3 KiB
Objective-C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// 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