发布时间:2018-04-11 编辑:钰歆博客 阅读(735)
$time 自定义的时间戳
1.当天
$begin=mktime(0,0,0,date('m',$time),date('d',$time),date('Y',$time));
$end=mktime(23,59,59,date('m',$time),date('d',$time),date('Y',$time));
$where['time']=array('between',array($begin,$end));
2.当月
$begin=mktime(0,0,0,date('m',$time),1,date('Y',$time));
$end=mktime(23,59,59,date('m',$time),date('t',$time),date('Y',$time));
$where['time']=array('between',array($begin,$end));
3.当年
$begin=mktime(0,0,0,1,1,date('Y',$time));
$end=mktime(0,0,0,1,1,date('Y',$time)+1)-1;
$where['time']=array('between',array($begin,$end));
4.时间戳 转换为 多少天多少小时前
function wordTime($time)
{
$time = (int) substr($time, 0, 10);
$int = time() - $time;
$str = '';
if ($int <= 2){
$str = sprintf('刚刚', $int);
}elseif ($int < 60){
$str = sprintf('%d秒前', $int);
}elseif ($int < 3600){
$str = sprintf('%d分钟前', floor($int / 60));
}elseif ($int < 86400){
$str = sprintf('%d小时前', floor($int / 3600));
}elseif ($int < 2592000){
$str = sprintf('%d天前', floor($int / 86400));
}else{
$str = date('Y-m-d H:i:s', $time);
}
return $str;
}
5.时间戳长度转成多长时间
function Sec2Time($time)
{
if(is_numeric($time)){
$value = array(
"years" => 0, "days" => 0, "hours" => 0,
"minutes" => 0, "seconds" => 0,
);
if($time >= 31556926){
$value["years"] = floor($time/31556926);
$time = ($time%31556926);
}
if($time >= 86400){
$value["days"] = floor($time/86400);
$time = ($time%86400);
}
if($time >= 3600){
$value["hours"] = floor($time/3600);
$time = ($time%3600);
}
if($time >= 60){
$value["minutes"] = floor($time/60);
$time = ($time%60);
}
$value["seconds"] = floor($time);
//return (array) $value;
$t=$value["years"] ."年". $value["days"] ."天"." ". $value["hours"] ."小时". $value["minutes"] ."分".$value["seconds"]."秒";
return $t;
}else{
return (bool) false;
}
}
标签:
下一篇:获取网卡地址