根据日期和时间显示内容

时间:2014-06-23 08:32:56

标签: php date time

我需要在某一天和某个时间显示内容。

我有一个脚本,我目前正在使用该脚本根据星期几显示内容,但需要将其扩展为在两个小时之间显示内容,所以内容在星期一上午12点到下午5点之后下午5点到11点59分之间,每周的每一天都是一样的。

<?php 
if( date( 'w' ) == 0 ) { 
?> 
<div>Write what you need to show here on Sunday</div> 
<? 
} 
if( date( 'w' ) == 1 ) { 
?> 
<div>Write what you need to show here on Monday</div>
<? 
} 
?> 
<? 
if( date( 'w' ) == 2 ) { 
?> 
<div>Write what you need to show here on Tuesday</div>
<? 
} 
?> 
<? 
if( date( 'w' ) == 3 ) { 
?> 
<div>Write what you need to show here on Wednesday</div> 
<? 
} 
?> 
<? 
if( date( 'w' ) == 4 ) { 
?> 
<div>Write what you need to show here on Thursday</div> 
<? 
} 
?> 
<? 
if( date( 'w' ) == 5 ) { 
?> 
<div>Write what you need to show here on Friday</div> 
<? 
} 
?> 
<? 
if( date( 'w' ) == 6 ) { 
?> 
<div>Write what you need to show here on Saturday</div> 
<? 
} 
?>

1 个答案:

答案 0 :(得分:1)

放下上午和下午,并在24小时内思考。

if (date('w') == 1) {
  if (date('H') >= 0 && date('H') < 17) {
    // the thing you want on monday 0:00 (12 am) to 17:00 (5pm)
  }
}
相关问题