最近蛋疼的在搞那个傻逼账号网,更新时间总想来点逼格,so机智的弄了个xxx前的样式,感觉逼格满满的
没错,这又是一个类似充数的**。。
直接上代码咯~
function agotime($ptime) { if(agotime=='1'){ $etime = time() - $ptime; if ($etime < 1) return '刚刚'; $interval = array ( 12 * 30 * 24 * 60 * 60 => '年前 ('.date('Y-m-d', $ptime).')', 30 * 24 * 60 * 60 => '个月前 ('.date('m-d', $ptime).')', 7 * 24 * 60 * 60 => '周前 ('.date('m-d', $ptime).')', 24 * 60 * 60 => '天前', 60 * 60 => '小时前', 60 => '分钟前', 1 => '秒前' ); foreach ($interval as $secs => $str) { $d = $etime / $secs; if ($d >= 1) { $r = round($d); return $r . $str; } } }elseif(agotime=='2'){ return date("Y-m-d H:i:s",$ptime); }
函数直接从我账号网的文件里机智复制来的,agotime()函数的时间需要是时间戳的形式
为了方便设定,我那个有个常量 agotime==1时是xxx前的
切记,时间是时间戳,其余就木有了~
更新时间总想来点逼格
2019年2月11日 17:45671824 678015I visited a great deal of site but I conceive this 1 holds something special in it in it 907771
2018年8月15日 23:54479738 620017Dead pent subject matter, thanks for entropy. 951439
2018年8月15日 18:10没错,if else反而影响性能,循环更好(老师这么说的)
2017年3月5日 11:03

2015年12月31日 15:09不知php效率如何,反正我在C语言里教徒弟的时候强调了能用if else的时候就不要用循环。
2015年12月28日 23:36循环还可以啊,反而if else不咋地
2016年1月1日 14:55