Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- - (NSString *)timeAgo:(NSDate *)compareDate{
- // NSDate *dd=@2015-05-27 11:15:05 +0000;
- NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
- [dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ssZ"];
- NSDate *date = [dateFormatter dateFromString:@"2015-05-27 11:15:05 +0000"];
- NSTimeInterval interval = [date timeIntervalSinceReferenceDate];
- interval = -[compareDate timeIntervalSinceNow];
- int temp = 0;
- NSString *result;
- if (interval < 60) {
- result = [NSString stringWithFormat:@"Just now"]; //less than a minute
- }else if((temp = interval/60) <60){
- result = [NSString stringWithFormat:@"%dm",temp]; //minutes ago
- }else if((temp = temp/60) <24){
- result = [NSString stringWithFormat:@"%dh",temp]; //hours ago
- }else{
- temp = temp / 24;
- result = [NSString stringWithFormat:@"%dd",temp]; //days ago
- }
- return result;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement