시간별이미지출력 이것좀봐주세요!~~ 정보
JavaScript 시간별이미지출력 이것좀봐주세요!~~본문
지금 시간대 별로 이미지를 출력하려고하는데요!~
소스를 이렇게했는데!~
내용은 아침 08:00~09:00 시까지 onair이라는이미지가
점심 12:00~01:00 시까지 onair이라는이미지가
저녁 05:00~06:00 시까지 onair이라는이미지가
그외의시간은 offair 이라는 이미지가 뜨게하고싶은데 이렇게 하는게 맞는지 고수분들께서좀 봐주세요!~~~
<?php 
$ctime = time(); 
$img = 0; 
$achimStart = strtotime(date("Y-m-d"). "08:00"); 
$achimEnd  = strtotime(date("Y-m-d"). "09:00"); 
$bchimStart = strtotime(date("Y-m-d"). "12:00"); 
$bchimEnd  = strtotime(date("Y-m-d"). "01:00"); 
$cchimStart = strtotime(date("Y-m-d"). "05:30"); 
$cchimEnd  = strtotime(date("Y-m-d"). "06:00"); 
// 아침인지.... 
if($ctime >= $achimStart && $ctime <= $achimEnd) $img = 1; 
// 점심인지.... 
if($ctime >= $bchimStart && $ctime <= $bchimEnd) $img = 1; 
// 저녁인지.... 
if($ctime >= $cchimStart && $ctime <= $cchimEnd) $img = 1; 
if($img == 1) echo "<img src=./img_u/onair.gif>"; 
else echo "<img src=./img_u/offair.gif>"; 
?>
0
댓글 2개

조금더 간편한 코드가 나올법했는데 말이죠. ㅎㅎ

switch( date('H')) {
case '08':
case '09':
case '12':
case '13':
case '17': if( date('i')<'30') break;
case '18': echo 'onair.gif';
}
?>