<pre class="c" name="code">
function countdown ($date1, $date2) {
$difference = strtotime($date1) - strtotime($date2);
if ($difference > 31536000) {
$due_date = sprintf('差距%d年', floor($difference / 31536000));
} elseif ($difference > 2592000) {
$due_date = sprintf('差距%d月', floor($difference / 2592000));
} elseif ($difference > 86400) {
$due_date = sprintf('差距%d天', floor($difference / 86400));
} elseif ($difference > 3600) {
$due_date = sprintf('差距%d小時', floor($difference / 3600));
} elseif ($difference > 60) {
$due_date = sprintf('差距%d分鐘', floor($difference / 60));
} elseif ($difference > 0) {
$due_date = sprintf('差距%d秒', $difference);
} else {
$due_date = '---';
}
return $due_date;
}