PHP 时间转换

转载请注明来源:https://www.cnblogs.com/hookjc/

function DateToTime($date)
{
 //如果已经是时间戳,需要直接返回
 if(is_numeric($date)) return $date;
 if($date=='') return 0;
 $a=explode(" ",$date);
 $b=explode("-",$a[0]);
 $c=explode(":",$a[1]);
 if($b[0]<0) $b[0]=1;
 if($b[1]=='') $b[1]=0;
 if($b[2]=='') $b[2]=1;
 if($c[0]=='') $c[0]=0;
 if($c[1]=='') $c[1]=0;
 if($c[2]=='') $c[2]=0;
 $time=mktime($c[0],$c[1],$c[2],$b[1],$b[2],$b[0]);
 return $time;
}

function TimetoDay($time)

 if($time=='') return time();
 $d = floor($time/3600/24);
 $h = floor(($time%(3600*24))/3600);
 $m = floor(($time%(3600*24)%3600)/60);
 return $d."天".$h."小时".$m."分钟";
}

来源:python脚本自动迁移

posted @ 2020-06-29 10:39  jiangcheng_15  阅读(217)  评论(0编辑  收藏  举报