php时间函数,即拿即用
时间差函数
function tranTime($time) { $rtime = date("m-d H:i", $time); $htime = date("H:i", $time); $time = time() - $time; if ($time < 60) { $str = '刚刚'; } elseif ($time < 60 * 60) { $min = floor($time / 60); $str = $min . '分钟前'; } elseif ($time < 60 * 60 * 24) { $h = floor($time / (60 * 60)); $str = $h . '小时前 ' . $htime; } elseif ($time < 60 * 60 * 24 * 3) { $d = floor($time / (60 * 60 * 24)); if ($d == 1) $str = '昨天 ' . $rtime; else $str = '前天 ' . $rtime; } else { $str = $rtime; } return $str; }
倒计时天数小时分秒函数
function get_countdown($unix_time = '') { if (empty($unix_time)) return false; if ($unix_time < time()) return array("day" => 0, "hour" => 0, "min" => 0, "sec" => 0); $timediff = $unix_time - time(); $days = intval($timediff / 86400); // 时间差算整天数 $remain = $timediff % 86400; //整除天数取余,余下来秒数 记作 A $hours = intval($remain / 3600); // 用A除3600 算整小时数 $remain = $remain % 3600; //用A整除小时取余数 记作B $mins = intval($remain / 60); // 用B除60算整分数 $secs = $remain % 60; // 用B整数分取余数 为剩下的秒数 $res = array("day" => $days, "hour" => $hours, "min" => $mins, "sec" => $secs); return $res; }
相关推荐
Greatemperor 2020-07-19
勇往直前 2020-05-17
igogo00 2020-05-15
CloudXli 2020-02-21
GoatSucker 2020-02-09
千锋 2020-01-29
assastor 2020-01-29
89510194 2020-01-18
llwang0 2019-12-28
azhou 2019-12-27
Airuio 2019-12-20
sunnyJam 2019-12-08
wyqwilliam 2019-11-12
Laozizuiku 2019-11-12
zhangpan 2019-11-10
sprintwind 2011-03-23
xianhe0 2010-08-25