- (NSString*) compareCurrentTime:(NSString*)str
{
? ? //把字符串轉(zhuǎn)為NSdate
? ? //? ? NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
? ? //? ? [formatter setDateFormat:@"YYYY-MM-dd HH:mm:ss"];
? ? //? ? currDate = [formatter stringFromDate:[NSDate date]];
? ? long long time = [str longLongValue];
? ? NSDate *d = [[NSDate alloc]initWithTimeIntervalSince1970:time/1000.0];
? ? NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
? ? [dateFormattersetDateFormat:@"yyyy-MM-dd HH:mm"];
? ? NSString*currentDateString = [dateFormatterstringFromDate:d];
? ? NSDate*currentDate = [NSDatedate];
? ? NSTimeIntervaltimeInterval = [currentDatetimeIntervalSinceDate:d];
? ? longtemp =0;
? ? NSString*result;
? ? if(timeInterval/60<1)
? ? {
? ? ? ? result = [NSString stringWithFormat:@"剛剛"];
? ? }
? ? elseif((temp = timeInterval/60) <60){
? ? ? ? result = [NSStringstringWithFormat:@"%ld分鐘前",temp];
? ? }
? ? elseif((temp = temp/60) <24){
? ? ? ? result = [NSStringstringWithFormat:@"%ld小時前",temp];
? ? }
? ? elseif((temp = temp/24) <30){
? ? ? result = [NSString stringWithFormat:@"%ld天前",temp];
?? ?}
? ? elseif((temp = temp/30) <12){
? ? ? ? result = [NSString stringWithFormat:@"%ld月前",temp]; ? ?}
? ? else{
? ? ? ? temp = temp/12;
? ? ? ? result = [NSString stringWithFormat:@"%ld年前",temp];
? ? }
? ? return? result;
}