-
-
Save JulesWang/888194 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function pretty_date($time) { | |
$diff = time() - $time; | |
$day_diff = floor($diff / 86400); | |
if(is_nan($day_diff)) return ''; | |
if ($day_diff == 0) { | |
if ($diff < 60) { | |
return $diff . "second ago"; | |
} else if ($diff < 120) { | |
return '1 min ago'; | |
} else if ($diff < 3600) { | |
return floor( $diff / 60 ) . " min ago"; | |
} else if ($diff < 7200) { | |
return '1 hour ago'; | |
} else if ($diff < 86400) { | |
return floor( $diff / 3600 ) . " hour ago"; | |
} | |
} else if ($day_diff == 1) { | |
return 'yesterday'; | |
} else if ($day_diff < 7) { | |
return $day_diff . " day ago"; | |
} else if ($day_diff < 31) { | |
return ceil( $day_diff / 7 ) . " week ago"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment