<?php header("Content-Type:text/html;charset=utf-8"); date_default_timezone_set(‘PRC‘); //设置中国时区 //获取当前时间 $n = date("Y-m-d H:i:s"); $now = strtotime(date("Y-m-d H:i:s")); //插入时间 $nnow = "1493782514"; $nn = date("Y-m-d H:i:s",$nnow); echo "当前时间:".$n."<br/> 当前时间戳:".$now."<br/> 插入时间:".$nn."<br/> 插入时间戳:".$nnow."<br/>"; //exit(); $r = ‘‘; $way = $now - $nnow; if($way < 60){ $r = ‘刚刚发布‘; }elseif($way >= 60 && $way <3600){ $r = floor($way/60).‘分钟前‘; }elseif($way >=3600 && $way <86400){ $r = floor($way/3600).‘小时前‘; }elseif($way >=86400 && $way <2592000){ $r = floor($way/86400).‘天前‘; }elseif($way >=2592000 && $way <15552000){ $r = floor($way/2592000).‘个月前‘; }else{ $r = "一年前"; } echo $r; ?>
时间: 2024-10-07 10:39:53