#import "NSDate+Extention.h"
@implementation NSDate (Extention)
+ (NSString *)nowFromDateExchange:(int)oldTime {
NSDate *date = [NSDate date];
NSTimeInterval currentTime= [date timeIntervalSince1970];
double timeDiffence = currentTime - oldTime;
if (timeDiffence <= 60) {
return [NSString stringWithFormat:@"%.0f 秒前",timeDiffence];
}else if (timeDiffence <= 3600){
return [NSString stringWithFormat:@"%.0f 分钟前",timeDiffence / 60];
}else if (timeDiffence <= 86400){
return [NSString stringWithFormat:@"%.0f 小时前",timeDiffence / 3600];
}else if (timeDiffence <= 604800){
return [NSString stringWithFormat:@"%.0f 天前",timeDiffence / 3600 /24];
}else{
NSDate *oldTimeDate = [NSDate dateWithTimeIntervalSince1970:oldTime];
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"yyyy-MM-dd"];
return [formatter stringFromDate:oldTimeDate];
}
}
@end
