$yes_start_time && $time < $yes_end_time) { return '昨天'; } if ($time > $yes_start_time && $time < $two_end_time) { return '1天前'; } if ($time > $yes_start_time && $time < $three_end_time) { return '2天前'; } if ($time > $yes_start_time && $time < $four_end_time) { return '3天前'; } if ($time > $yes_start_time && $time < $five_end_time) { return '4天前'; } if ($time > $yes_start_time && $time < $six_end_time) { return '5天前'; } if ($time > $yes_start_time && $time < $seven_end_time) { return '6天前'; } switch ($format) { case 'd': $show_time = date('Y-m-d', $time); break; case 'i': $show_time = date('Y-m-d H:i', $time); break; case 's': $show_time = date('Y-m-d H:i:s', $time); break; } return $show_time; } /** * 计算两个时间戳之间相差的时间 * * $differ = self::differ(60, 182, 'minutes,seconds'); // array('minutes' => 2, 'seconds' => 2) * $differ = self::differ(60, 182, 'minutes'); // 2 * * @param int $remote timestamp to find the span of * @param int $local timestamp to use as the baseline * @param string $output formatting string * @return string when only a single output is requested * @return array associative list of all outputs requested * @from https://github.com/kohana/ohanzee-helpers/blob/master/src/Date.php */ public static function differ($remote, $local = null, $output = 'years,months,weeks,days,hours,minutes,seconds') { // Normalize output $output = trim(strtolower((string)$output)); if (!$output) { // Invalid output return false; } // Array with the output formats $output = preg_split('/[^a-z]+/', $output); // Convert the list of outputs to an associative array $output = array_combine($output, array_fill(0, count($output), 0)); // Make the output values into keys extract(array_flip($output), EXTR_SKIP); if ($local === null) { // Calculate the span from the current time $local = time(); } // Calculate timespan (seconds) $timespan = abs($remote - $local); if (isset($output['years'])) { $timespan -= self::YEAR * ($output['years'] = (int)floor($timespan / self::YEAR)); } if (isset($output['months'])) { $timespan -= self::MONTH * ($output['months'] = (int)floor($timespan / self::MONTH)); } if (isset($output['weeks'])) { $timespan -= self::WEEK * ($output['weeks'] = (int)floor($timespan / self::WEEK)); } if (isset($output['days'])) { $timespan -= self::DAY * ($output['days'] = (int)floor($timespan / self::DAY)); } if (isset($output['hours'])) { $timespan -= self::HOUR * ($output['hours'] = (int)floor($timespan / self::HOUR)); } if (isset($output['minutes'])) { $timespan -= self::MINUTE * ($output['minutes'] = (int)floor($timespan / self::MINUTE)); } // Seconds ago, 1 if (isset($output['seconds'])) { $output['seconds'] = $timespan; } if (count($output) === 1) { // Only a single output was requested, return it return array_pop($output); } // Return array return $output; } /** * 获取指定年月拥有的天数 * @param int $month * @param int $year * @return false|int|string */ public static function days_in_month($month, $year) { if (function_exists("cal_days_in_month")) { return cal_days_in_month(CAL_GREGORIAN, $month, $year); } else { return date('t', mktime(0, 0, 0, $month, 1, $year)); } } }