You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
67 lines
1.8 KiB
67 lines
1.8 KiB
// |
|
// XHAlbum.m |
|
// MessageDisplayExample |
|
// |
|
// Created by HUAJIE-1 on 14-5-19. |
|
// Copyright (c) 2014年 曾宪华 开发团队(http://iyilunba.com ) 本人QQ:543413507 本人QQ群(142557668). All rights reserved. |
|
// |
|
|
|
#import "XHAlbum.h" |
|
#import "myHelper.h" |
|
|
|
@implementation XHAlbum |
|
|
|
- (NSString *)getTimeStr{ |
|
if ([_timestamp timeIntervalSinceNow] < - 24 * 60 * 60) { |
|
return [myHelper getDateFormatWithStr:@"M月d日" date:_timestamp]; |
|
}else{ |
|
return [self secToStr:[_timestamp timeIntervalSinceNow] showSec:NO]; |
|
} |
|
} |
|
|
|
|
|
- (NSMutableString *)secToStr:(int)sec showSec:(BOOL)showSec{ |
|
sec = -sec; |
|
NSMutableString *timeStr = [NSMutableString string]; |
|
|
|
if (sec < 60 * 5) { |
|
[timeStr appendString:@"刚刚"]; |
|
return timeStr; |
|
} |
|
|
|
int day = sec / (60 * 60 * 24); |
|
sec -= day * 60 * 60 * 24; |
|
int ousr = sec / (60 * 60); |
|
sec -= ousr * 60 * 60; |
|
int minutes = sec / 60; |
|
sec -= minutes * 60; |
|
|
|
if (day > 0) { |
|
[timeStr appendString:[NSString stringWithFormat:@"%d天",day]]; |
|
} |
|
if (ousr > 0) { |
|
[timeStr appendString:[NSString stringWithFormat:@"%d小时",ousr]]; |
|
} |
|
if (day > 0) { |
|
[timeStr appendString:[NSString stringWithFormat:@"%d分",minutes]]; |
|
[timeStr appendString:@"前"]; |
|
return timeStr; |
|
} |
|
if (showSec) { |
|
if (sec < 10) { |
|
[timeStr appendString:[NSString stringWithFormat:@"%d分0%d秒",minutes,sec]]; |
|
}else{ |
|
[timeStr appendString:[NSString stringWithFormat:@"%d分%d秒",minutes,sec]]; |
|
} |
|
}else{ |
|
if (sec < 10) { |
|
[timeStr appendString:[NSString stringWithFormat:@"%d分",minutes]]; |
|
}else{ |
|
[timeStr appendString:[NSString stringWithFormat:@"%d分",minutes]]; |
|
} |
|
} |
|
[timeStr appendString:@"前"]; |
|
return timeStr; |
|
} |
|
|
|
@end
|
|
|