Home > php教程 > php手册 > 消息发布时间距今天数计算函数

消息发布时间距今天数计算函数

WBOY
Release: 2016-06-07 11:42:34
Original
1193 people have browsed it

计算给定时间戳与当前时间相差的时间,并以一种比较友好的方式输出
/**<br>  * 计算给定时间戳与当前时间相差的时间,并以一种比较友好的方式输出<br>  * @param  [int] $timestamp [给定的时间戳]<br>  * @param  [int] $current_time [要与之相减的时间戳,默认为当前时间]<br>  * @return [string]            [相差天数]<br>  */<br> function tmspan($timestamp,$current_time=0){<br>     if(!$current_time) $current_time=time();<br>     $span=$current_time-$timestamp;<br>     if($span         return "刚刚";<br>     }else if($span         return intval($span/60)."分钟前";<br>     }else if($span         return intval($span/3600)."小时前";<br>     }else if($span         return intval($span/(24*3600))."天前";<br>     }else{<br>         return date('Y-m-d',$timestamp);<br>     }<br> }

AD:真正免费,域名+虚机+企业邮箱=0元

source:php.cn
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