时间日期函数的操作
1 <?php 2 echo date('Y-m-d',strtotime("+ 4 month",strtotime('2013-05-31'))); 3 $str_nums='2013-05-28:2013-06-10,10,0|2013-05-30:2013-05-31,15,0|2013-05-31:2013-05-31,15,1|2013-05-31:2013-05-31,15,2'; 4 $str_nums_arr=explode('|',$str_nums); 5 foreach($str_nums_arr as $k1=>$v1) 6 { 7 $arr2=explode(',',$v1); 8 var_dump($arr2); 9 $arr3=explode(':',$arr2[0]); 10 echo '开始日期:',$arr3[0],'结束日期:',$arr3[1],'<br>'; 11 if($arr2[2] == 0) 12 { 13 echo '开始时间戳:',$start=strtotime($arr3[0]),'——'; 14 echo '结束时间戳:',$end=strtotime($arr3[1]),'<br>'; 15 $i=0; 16 while($i<=($end-$start)/86400) 17 //while($mid <= $end) 18 { 19 $mid=$start+$i*86400; 20 echo $mid,'房数是:',$arr2[1].'%%<br>'; 21 //echo $mid,'&&<br>'; 22 ++$i; 23 } 24 } 25 elseif($arr2[2] == 1)//每周循环 26 { 27 echo '当前日期时间戳',$start=strtotime($arr3[0]),'<br>'; 28 $ii=0; 29 while($ii < 4)//1个月循环4周 30 { 31 $mid=$start+$ii*7*86400; 32 echo $ii,'周后时间戳是',$mid,'房数是:',$arr2[1].'%%<br>'; 33 ++$ii; 34 } 35 } 36 elseif($arr2[2] == 2) 37 { 38 $iii=0; 39 while($iii < 6) 40 { 41 echo '当前日期时间戳',$start=strtotime($arr3[0]),'<br>'; 42 $day=date('d', $start); 43 $next_day=date('d', strtotime("+ $iii month",$start)); 44 if($day == $next_day) 45 { 46 echo $iii,"个月后时间戳",$mid=strtotime("+ $iii month",$start),'<br>'; 47 }else{ echo $iii,'个月后没有这一天则跳过<hr>';} 48 ++$iii; 49 50 } 51 } 52 } 53 54 55 56 function weekday($time) 57 { 58 if(is_numeric($time)) 59 { 60 $weekday = array('星期日','星期一','星期二','星期三','星期四','星期五','星期六'); 61 return $weekday[date('w', $time)]; 62 } 63 return false; 64 } 65 ?>
通过时间戳获取星期:
<li><span>入住日期:</span><div><?php echo date('Y-m-d', $room_book->date_in).' 星期'. convert_week_num(date('N', $room_book->date_in));?></div></li>
<?php
function convert_week_num($num = 0){
$week_arr = array(
'1' => '一',
'2' => '二',
'3' => '三',
'4' => '四',
'5' => '五',
'6' => '六',
'7' => '日',
);
return isset($week_arr[$num]) ? $week_arr[$num] : '';
}
?>