PHP解决方案@时间差异计算函数
生活随笔
收集整理的這篇文章主要介紹了
PHP解决方案@时间差异计算函数
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
為什么80%的碼農(nóng)都做不了架構(gòu)師?>>> ??
方案解決目標(biāo):計算時間差異
function ago($time){
? $periods = array("second","minute","hour","day","week","month","year","decade");
? $lengths = array("60","60","24","7","4.35","12","10");
? $now = time();
? ? ? $difference ? ? = $now - $time;
? ? ? $tense ? ? ? ? ="ago";for($j =0; $difference >= $lengths[$j]&& $j < count($lengths)-1; $j++){
? ? ? $difference /= $lengths[$j];}
? $difference = round($difference);if($difference !=1){
? ? ? $periods[$j].="s";}return"$difference $periods[$j] 'ago' ";}
轉(zhuǎn)載于:https://my.oschina.net/rongx/blog/481544
總結(jié)
以上是生活随笔為你收集整理的PHP解决方案@时间差异计算函数的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: eclipse 使用指南
- 下一篇: 注册Tomcat服务为系统服务