更多>>PHP程序设计 Blog
来源:一度好 时间:2016-09-29 阅读:3116
用PHP写一个函数,在给定的日期中,把本周的日期全部列出来。
函数名称:给定日期,获取本周内的日期
参数说明:day: 给定的日期, week:是否显示星期, week_type:显示星期的格式
function week_day($day, $week = true, $week_type = 1){
$week_arr = array( '1'=>'周一', '2'=>'周二', '3'=>'周三', '4'=>'周四', '5'=>'周五', '6'=>'周六', '7'=>'周日', );
$week_arr2 = array( '1'=>'星期一', '2'=>'星期二', '3'=>'星期三', '4'=>'星期四', '5'=>'星期五', '6'=>'星期六', '7'=>'星期日', );
$whichD = date('N',strtotime($day));
$weeks = array();
for($i = 1; $i <= 7; $i++){
if($i < $whichD){
$date = strtotime($day)-($whichD-$i)*24*3600;
}else{
$date = strtotime($day)+($i-$whichD)*24*3600;
}
$weeks[$i] = date('Y-m-d',$date);
if($week == true){
if($week_type == 1){
$weeks[$i] .= ' '.$week_arr[$i];
}else{
$weeks[$i] .= ' '.$week_arr2[$i];
}
}
}
return $weeks;
}
使用说明:
print_r( week_day('2016-09-29', $week = true, $week_type = 1) );
输出值如下:
评论列表 |
暂时没有相关记录
|
发表评论