动态详情

This commit is contained in:
fengshuo
2022-06-22 20:38:57 +08:00
parent fe8747ce5e
commit 365b8aa2da
27 changed files with 1237 additions and 77 deletions

View File

@@ -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"];
// 1010
NSDateFormatter *timeFormatter = [[NSDateFormatter alloc] init];
[timeFormatter setDateFormat:@"HH:mm"];
// 218
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 <60n
} else if((temp = timeInterval/aMinute) < 60){
return [NSString stringWithFormat:@"%ld分钟前",temp];
// C. n60xx:xx
} else if((temp = temp/60) < 24 && isSameDay){
return [timeFormatter stringFromDate:date];
// C. n60xx: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