2010-07-16 52 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!';}