- function plural($num) {
- if ($num != 1)
- return "s";
- }
-
- function getRelativeTime($date) {
- $diff = time() - strtotime($date);
- if ($diff return $diff . " second" . plural($diff) . " ago";
- $diff = round($diff/60);
- if ($diff return $diff . " minute" . plural($diff) . " ago";
- $diff = round($diff/60);
- if ($diff return $diff . " hour" . plural($diff) . " ago";
- $diff = round($diff/24);
- if ($diff return $diff . " day" . plural($diff) . " ago";
- $diff = round($diff/7);
- if ($diff return $diff . " week" . plural($diff) . " ago";
- return "on " . date("F j, Y", strtotime($date));
- }
复制代码
|