時間差函數
<code>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; } </code>
倒數天數小時分秒函數
<code>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; } </code>
以上就介紹了php時間函數,也就是拿即用,包含了面向的內容,希望對PHP教學有興趣的朋友有幫助。