2011-12-18 78 views

回答

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

+0

什么我想要做的是,展现的timeleft并检查是否比国际日期变更线更行已过期。 – 2011-12-18 07:02:12

+0

@rails_noob - 请参阅编辑。 – 2011-12-18 07:18:15

+0

真棒。我需要修改,因为它没有显示以小时为单位的到期时间。但没关系。谢谢 – 2011-12-18 07:27:44

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);