codepad
[
create a new paste
]
login
|
about
Language:
C
C++
D
Haskell
Lua
OCaml
PHP
Perl
Plain Text
Python
Ruby
Scheme
Tcl
<?php //facebook like past time display function facebook_style_date_time($timestamp){ $difference = time() - $timestamp; $periods = array("sec", "min", "hour", "day", "week", "month", "years", "decade"); $lengths = array("60","60","24","7","4.35","12","10"); if ($difference > 0) { // this was in the past time $ending = "ago"; } else { // this was in the future time $difference = -$difference; $ending = "to go"; } for($j = 0; $difference >= $lengths[$j]; $j++) $difference /= $lengths[$j]; $difference = round($difference); if($difference != 1) $periods[$j].= "s"; $text = "$difference $periods[$j] $ending"; return $text; } $my_time_stamp = "1346913040"; echo facebook_style_date_time($my_time_stamp); echo "\n"; ?>
Private
[
?
]
Run code
Submit