Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- +(NSString *)getTimeAgo:(NSDate *)fecha
- {
- NSString *timeAgo;
- float since_mins,since_hours, since_days, since_months, since_years;
- NSTimeInterval since = fabs([fecha timeIntervalSinceNow]);
- since_mins = (since / 60);
- since_hours = (since_mins / 60);
- since_days = (since_hours / 24);
- since_months = (since_days / 31);
- since_years = (since_months / 365);
- if(since_years >= 1) timeAgo = [NSString stringWithFormat:@"%.f %@",floor(since_years), floor(since_years)==1?@" year ago":@" years ago"];
- else if(since_months >= 1) timeAgo = [NSString stringWithFormat:@"%.f %@",floor(since_months), floor(since_months)==1?@" month ago":@" months ago"];
- else if(since_days >= 1) timeAgo = [NSString stringWithFormat:@"%.f %@",floor(since_days), floor(since_days)==1?@" day ago":@" days ago"];
- else if(since_hours >= 1) timeAgo = [NSString stringWithFormat:@"%.f %@",floor(since_hours), floor(since_hours)==1?@" hour ago":@" hours ago"];
- else if(since_mins >= 1) timeAgo = [NSString stringWithFormat:@"%.f %@",floor(since_mins), floor(since_mins)==1?@" minute ago":@" minutes ago"];
- else if(since == 60) timeAgo = @"1 minute ago";
- else timeAgo = [NSString stringWithFormat:@"%.f %@", since, floor(since_mins)==1?@" second ago":@" seconds ago"];
- return timeAgo;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement