How to convert NSDate in to relative format as “Today”,”Yesterday”,”a week ago”,”a month ago”,”a year ago”?

For simplicity I’m assuming that the dates you are formatting are all in the past (no “tomorrow” or “next week”). It’s not that it can’t be done but it would be more cases to deal with and more strings to return. You can use components:fromDate:toDate:options: with whatever combination of date components you are looking for … Read more

PHP: producing relative date/time from timestamps

This function gives you “1 hour ago” or “Tomorrow” like results between ‘now’ and ‘specific timestamp’. function time2str($ts) { if(!ctype_digit($ts)) $ts = strtotime($ts); $diff = time() – $ts; if($diff == 0) return ‘now’; elseif($diff > 0) { $day_diff = floor($diff / 86400); if($day_diff == 0) { if($diff < 60) return ‘just now’; if($diff < 120) … Read more