Home > php教程 > php手册 > 一个php日期函数,显示为n小时前发表

一个php日期函数,显示为n小时前发表

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-21 08:57:30
Original
1114 people have browsed it

比如把: “2009-02-14 18:50 发表”<br>转成:“一个小时前发表”<br>

<?php <br/>function format_date($date)<br>{<br>    $limit = time() - $date;<br>    if($limit     {<br>        return $limit . '秒钟之前';<br>    }<br>    if($limit >= 60 && $limit     {<br>        return floor($limit/60) . '分钟之前';<br>    }<br>    if($limit >= 3600 && $limit     {<br>        return floor($limit/3600) . '小时之前';<br>    }<br>    if($limit >= 86400)<br>    {<br>        return date('Y-m-d H:i:s', $date);<br>    }<br>}<br>$time = 1234613275;<br>echo format_date($time);<br>?>



Related labels:
Statement of this Website
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template