function week_day($week,$day,$year){
//第一步算出第几周一共有多少天
$first_week = date('w',strtotime($year.'-01-01')) == 0 ? 7 : date('w',strtotime($year.'-01-01'));
$total_days = $week == 1 ? $day : (($week-2)*7+$day+(7-$first_week)+1);
//递减每个月天数
for($i=1;$i<=12;$i++){
$month_num = date('t',strtotime($year.'-'.($i>9 ? $i : '0'.$i).'-01'));
//$total_days = $total_days > $month_num ? ($total_days-$month_num) : $total_days;
if($total_days>$month_num){
$total_days = $total_days-$month_num;
}else{
break;
}
}
return $year.'-'.($i>9 ? $i : '0'.$i).'-'.($total_days > 9 ? $total_days : '0'.$total_days);
}
function mathweek( $today )
{
//一年开始是星期几
$first_week = date('w',strtotime(date('Y',strtotime($today)).'-01-01')) == 0 ? 7 : date('w',strtotime(date('Y',strtotime($today)).'-01-01'));
//算出本年到$today一共有几天$total_days
// $month = date('m',strtotime($today));
// $day = date('d',strtotime($today));
// $year = date('Y',strtotime($today));
// $total_days = 0;
// for($i=1;$i<intval($month);$i++){//echo '第'.$i.'个月有'.date('t',strtotime("$year-$i-01")).'天<br>';
// $total_days += date('t',strtotime("$year-$i-01"));
// }
// $total_days = $total_days+intval($day);
$total_days = date('z',strtotime($today));
//除去第一周不规则周
$total_days = $total_days-(7-$first_week);
if($total_days%7==0){
$days = $total_days/7+1;
}else{
$days = ceil($total_days/7)+1;
}
return $days;
}
|