🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
``` /** * 格式化时间 * @param int $time 时间戳 * @return string */ function formatDate($time='default') { $date = $time == 'default' ? date('Y-m-d H:i:s', time()) : date('Y-m-d H:i:s', $time); return $date; } /** * 时间倒计时格式化 * @param int $time 时间戳 * @return string */ function poorDate($time1='default',$time2='default') { $time1= $time1=='default'?time():$time1; $time2= $time2=='default'?time():$time2; $cc=$time2 - $time1; // var_dump($cc);die; $sub2=0; if($cc<-86400){ // var_dump($cc);die; $sub2 = ceil(($time2 - $time1)/86400); }else if($cc>86400) { $sub2 = floor(($time2 - $time1)/86400); } $h=$cc-$sub2*86400; if($h<-3600){ $sub1 = ceil($h/3600); }else if($h>3600) { $sub1 = floor($h/3600); } $i=$h-$sub1*3600; if($i<-60){ $sub = ceil($i/60); }else if($cc>60) { $sub = floor($i/60); } $s=$i-$sub*60; return ["d"=>$sub2,"H"=>$sub1,"i"=>$sub,"s"=>$s]; } ```