+(NSString *)getTime:(NSString *)timeSource
{
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat: @"yyyy-MM-dd HH:mm:ss"];
NSDate *date = [dateFormatter dateFromString:timeSource];
NSTimeInterval sec = [date timeIntervalSinceNow];
if (- sec < 86400) {
if (- sec >= 3600) {
int t = - sec / 3600;
return [NSString stringWithFormat:@"%d小時(shí)前",t];
}else if (-sec >60) {
int t = - sec / 60 ;
return [NSString stringWithFormat:@"%d分鐘前",t];
}else {
return [NSString stringWithFormat:@"%0.f秒前",- sec];
}
}else {
[dateFormatter setDateFormat: @"yyyy年MM月dd日"];
return [dateFormatter stringFromDate:date];
}
}