2013-01-31 2 views
1

나는 단지 내 시간표 스크립트의 일부 (일을 다루는 부분)PHP는 시간표의 날 문제

내 시간표 (일상은 목요일이되었다) 월말까지 잘 작동 알게되었다

등을 포함 시켰습니다 그래서 나는 대본으로 돌아갔다. 그리고 나는 나의 시간표가 새로운 달인지를 언제 알 수 있을지 모르기 때문에 그것이 존재하지 않는 카운터 31, 32, 33 (날의 일)처럼 계속 행동한다. 왜 그것은 나를 목요일로 매일주고 1970 년이 1970 년이라고 말하고있는 것입니까?

시간표는 오늘부터 5 일을 보여줍니다. 그래서 오늘과 다른 4 시간을 보여줍니다. 금요일, 토요일, 일요일, 월요일. 솔루션 혹은 스크립트 이런 종류의 작업을 수행하는 쉬운 방법이

 <?php 
    } 
    $timein = time(); 
    $d7 = date("H", $timein); 
    $d6 = ($d7 +1) - 4; 
    $d1 = date("d", $timein); 

    $d2 = date("F", $timein); 
    $d3 = date("Y", $timein); 
    $d4 = "$d2 $d3"; 
    $d5 = $d1 + 4; 
    for($i = $d1; $i <= $d5; $i++) { 
    $day = strtotime("{$i} {$d4}"); 
    $day = date("d/m/Y", $day); 

    ?> 
    <table border="0" cellspacing="0" cellpadding="0" width="20%" style="float: left;"> 
    <tr><td> 
     <div class="square title" style="padding: 3px; -webkit-border-radius: 4px; -moz-border-radius: 4px; border-radius: 4px; width: 92%; text-align: center; bottom: 5px; margin-bottom: 5px; cursor: pointer; background: #79CDCD;"> 

      <strong><?php echo $day; ?></strong> 

     </div> 
</td></tr> 
</table> 
<? } ?> 

거기에 다음과 같이

내 코드는?

미리 도움을 주셔서 감사합니다.

답변

1

하루를 늘리기 위해 $timein에 86400 초를 추가하는 것은 어떻습니까?

+0

일광 절약 시간제를 잊었습니다. – Mike

+0

'time()'은 GMT입니다. – Kermit

+0

네 말이 맞아. 신경 쓰지 마. – Mike

0

당신은 자정 현재의 값을 얻을 수 strtotime를 사용에 $i일을 추가 할 수 있습니다 njk 당신은 또한 86,400초의 배수를 추가하여 작업을 수행 할 수 있습니다 제안으로 루프

<?php 

    for($i = 0; $i < 5; $i++) { 
     $day = strtotime("today + $i days"); 
     $day = date("d/m/Y", $day); 

     ?> 
     <table border="0" cellspacing="0" cellpadding="0" width="20%" style="float: left;"> 
      <tr> 
       <td> 
        <div class="square title" style="padding: 3px; -webkit-border-radius: 4px; -moz-border-radius: 4px; border-radius: 4px; width: 92%; text-align: center; bottom: 5px; margin-bottom: 5px; cursor: pointer; background: #79CDCD;"> 
         <strong><?php echo $day; ?></strong> 
        </div> 
       </td> 
      </tr> 
     </table> 
<? } ?> 
0

을 위해.

<?php 

for($i = 0; $i < 5; $i++) { 
    $day = time() + ($i * 86400); 
    $day = date("d/m/Y", $day); 

    ?> 
    <table border="0" cellspacing="0" cellpadding="0" width="20%" style="float: left;"> 
     <tr> 
      <td> 
       <div class="square title" style="padding: 3px; -webkit-border-radius: 4px; -moz-border-radius: 4px; border-radius: 4px; width: 92%; text-align: center; bottom: 5px; margin-bottom: 5px; cursor: pointer; background: #79CDCD;"> 
        <strong><?php echo $day; ?></strong> 
       </div> 
      </td> 
     </tr> 
    </table> 
<? } ?> 
1

코드가 매우 어려워 보입니다. 그것은 대개 좋은 징조가 아닙니다. 일반적으로 날짜를 처리 할 때 더 많은 객체 지향 접근법을 선호합니다.

$date = new DateTime(); 

for ($i = 0; $i <= 4; $i++) { 
    ?> 
    <table border="0" cellspacing="0" cellpadding="0" width="20%" style="float: left;"> 
    <tr><td> 
     <div class="square title" style="padding: 3px; -webkit-border-radius: 4px; -moz-border-radius: 4px; border-radius: 4px; width: 92%; text-align: center; bottom: 5px; margin-bottom: 5px; cursor: pointer; background: #79CDCD;"> 

      <strong><?php echo $date->format('d/m/Y'); ?></strong> 

     </div> 
    </td></tr> 
    </table> 
    <?php 
    $date->add(new DateInterval('P10D')); 
}