如何打印剩余时间

时间:2011-12-18 06:42:58

标签: php time

enter image description here

这是我的桌子。 日期行列以小时为单位。

如何根据日期行,created_at和当前时间打印剩余时间?

2 个答案:

答案 0 :(得分:1)

您可以使用strtotime()

<?php

$created = 1323504315;
$timeleft = 144;
$expires = strtotime("+$timeleft hours", $created);

$compare_text = "created: " . date('m/d/Y H:i A',$created) . ", now: " . date('m/d/Y H:i A') . " > expires:" . date('m/d/Y H:i A',$expires);

if (mktime() > $expires) {
    echo "The time has expired. ($timeleft, $compare_text)";
} else {
    echo "The time has not expired. ($timeleft, $compare_text)";
}

?>

http://codepad.org/WcCObV1z

答案 1 :(得分:0)

$hours = "144"; //from dataline
$totalHours = date("H") - $hours;

$totalMinutes = date("i");

$totalSeconds = date("s");

$totalMonths = date("m");

$totalDays = date("d");

$totalYears = date("Y");

$timeStamp = mktime($totalHours, $totalMinutes, $totalSeconds, $totalMonths, $totalDays, $totalYears);

$myTime = date("H:i A", $timeStamp);