2011-09-30 41 views
-3

我需要一些PHP的幫助PHP倒計時 - 如何使用否則如果幾個小時時,有不到1天離開

這裏是我的代碼

<?php 
    // Define your target date here 
    $targetYear = get_theme_option('episode_countdown_year'); 
    $targetMonth = get_theme_option('episode_countdown_month'); 
    $targetDay = get_theme_option('episode_countdown_day'); 
    $targetHour = 21; 
    $targetMinute= 00; 
    $targetSecond= 00; 
    date_default_timezone_set ("America/New_York"); 
    // Sets the default time zone, in this case GMT -08 

    $dateFormat = ("Y-m-d H:i:s"); 
    // Check the PHP Documentation for date uses. 
    $targetDate = mktime (
       $targetHour, 
       $targetMinute, 
       $targetSecond, 
       $targetMonth, 
       $targetDay, 
       $targetYear 
    ); 
    // Sets up our timer 
    $actualDate = time(); 
    // Gets the actual date 
    $secondsDiff = $targetDate - $actualDate; 
    // Finds the difference between the target date and the actual date 
    // These do some simple arithmatic to get days, hours, and minutes out of seconds. 
    $remainingDay = floor ($secondsDiff/60/60/24); 
    $remainingHour = floor (($secondsDiff - ($remainingDay 
       *60 * 60 * 24))/60/60); 
    $remainingMinutes = floor (($secondsDiff - ($remainingDay 
       *60 * 60 * 24) - ($remainingHour * 60 * 60))/60); 
    $remainingSeconds = floor (($secondsDiff - ($remainingDay 
       *60 * 60 * 24) - ($remainingHour * 60 * 60)) - 
       ($remainingMinutes * 60)); 

    $targetDateDisplay = date($dateFormat,$targetDate); 
    $actualDateDisplay = date($dateFormat,$actualDate); 
    // Sets up displays of actual and target 
    ?> 
     <?php if($targetDate > $actualDate) {?> 
     description: '<?php echo $remainingDay; ?> Day(s)/<?php echo $remainingHour; ?> Hour(s)/<?php echo $remainingMinutes; ?> Minute(s) Left..', 
     picture: '<?php echo $my_url ?>/cache/image-<?php echo $remainingDay; ?>-d.png' 
       <?php } else { ?> 
     description: 'Now Showing!', 
       picture: '<?php echo $my_url ?>/image-now.php' 
     <?php } ?> 

我的問題是

如何我可以添加其他代碼,如果還有不到1天

所以我可以隱藏剩餘日期,所以只有小時和分鐘顯示

我試過,但沒有工作

<?php } else if($remainingDay < $actualDate) {?> 

回答

0

無需?>後立即對線<?php,只要保持開放。但如果你只是想爲不到一天的時間碼,請嘗試:(對不起,我編了這麼多)

<?php if($targetDate > $actualDate) { 
    if($remainingHour < 24){  //main change here.. 
     //have < 1 day code here 
    } else { 
     echo "description: '$remainingDay Day(s)/$remainingHour Hour(s)/$remainingMinutes Minute(s) Left..' 
     picture: '$my_url /cache/image-$remainingDay-d.png'"; 
    } else { ?> 
    description: 'Now Showing!', 
    picture: '<?php echo $my_url ?>/image-now.php' 
    <?php } ?> 
+0

不起作用,試了一下 – LCallaghan84

+0

使用的邏輯,而不是確切的代碼。這是怎麼回事? –

+0

現在的作品 - 感謝您的幫助 – LCallaghan84

相關問題