Home  >  Article  >  Backend Development  >  PHP formatting time, minutes ago, hours ago

PHP formatting time, minutes ago, hours ago

WBOY
WBOYOriginal
2016-07-25 08:42:53843browse
  1. //Format time, minutes ago, hours ago
  2. function format_date($time){
  3. $t = time()-$time;
  4. $f = array(
  5. '31536000 '=>'Year',
  6. '2592000'=>'Month',
  7. '604800'=>'Week',
  8. '86400'=>'Day',
  9. '3600'=>' Hours',
  10. '60'=>'Minutes',
  11. '1'=>'Seconds'
  12. );
  13. foreach($f as $k=>$v){
  14. if(0 != $c = floor($t/(int)$k)){
  15. return $c.$v.'front';
  16. }
  17. }
  18. }
  19. echo format_date('1405959031');
  20. ?>
Copy code

A few minutes, PHP


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn