2010-07-16 49 views

回答

5

你必須得到當前時間戳,使用time()功能。

然後,您必須獲得12am的時間戳,例如使用strtotime()函數。

然後,減去這兩個值;如果結果的絕對值X,那麼它是正確的時間爲您;-)

+0

啊,你的「教一個人釣魚」的學校:)好的呼叫 – hookedonwinter 2010-07-16 21:27:34

0
<?php 
    $noon = strtotime("noon"); 
    $midnight = strtotime("midnight"); 

    $timeToMidnight = $midnight - date(); 
    $timeToNoon = $noon - time(); 
?> 
0
<?php 

function timeDiff($firstTime,$lastTime) 
{ 

// convert to unix timestamps 
$firstTime=strtotime($firstTime); 
$lastTime=strtotime($lastTime); 

// perform subtraction to get the difference (in seconds) between times 
$timeDiff=$lastTime-$firstTime; 

// return the difference 
return $timeDiff; 
} 

//Usage : 
echo timeDiff("2002-04-16 10:00:00","2002-03-16 18:56:32"); 

?> 
0
<?php 
$time = time(); 
if((date("g", $time) % 12) * 3600 
    + preg_replace('/^0/', '', date("i", $time)) * 60 
    + preg_replace('/^0/', '', date("s", $time)) 
    > $selected_time) { 

    // do whatever 

} 
?> 
0

這應該工作,對吧?

$ time = time(); 如果((日期( 「G」,$時間)== 12)& &(日期( 「我」,$時間)< 10)){回聲 'W00T!';}