2011-10-14 122 views
0

我試圖使用jQuery倒計時(http://code.google.com/p/jquery-countdown/)來顯示倒數到特定的日期和時間,但你需要編程jQuery調用的天數,小時數,分鐘數和秒數。PHP/JQuery/JavaScript倒計時

我不太清楚如何在JS中做到這一點,但我想通過PHP來計算時間,然後讓它插入這些變量將工作。我在網上找到了這個PHP函數,但我不確定添加$ seconds_left的算法。有人可以幫忙嗎?

function countdown($year, $month, $day, $hour, $minute) 
{ 
    // make a unix timestamp for the given date 
    $the_countdown_date = mktime($hour, $minute, 0, $month, $day, $year, -1); 

    // get current unix timestamp 
    $today = time(); 

    $difference = $the_countdown_date - $today; 
    if ($difference < 0) $difference = 0; 

    global $days_left; 
    global $hours_left; 
    global $minutes_left; 

    $days_left = floor($difference/60/60/24); 
    $hours_left = floor(($difference - $days_left*60*60*24)/60/60); 
    $minutes_left = floor(($difference - $days_left*60*60*24 - $hours_left*60*60)/60); 
} 

謝謝!

回答

1

你應該能夠得到秒左:

$seconds_left = floor($difference - $days_left*60*60*24 - $hours_left*60*60 - $minutes_left*60); 

應該得到你正在尋找(假設其餘代碼工作正常秒,我承認我的天堂沒有測試過)。