在php中按周获取每月的开始日期和结束日期
如何按月份、年份和周数计算一周的开始和结束日期?年份为4位整数,如2016年;月份为整数,范围为1-12;周是1-5范围内的整数 我已经有了这个代码块:在php中按周获取每月的开始日期和结束日期,php,date,Php,Date,如何按月份、年份和周数计算一周的开始和结束日期?年份为4位整数,如2016年;月份为整数,范围为1-12;周是1-5范围内的整数 我已经有了这个代码块: function getStartAndEndDate($week, $year) { $time = strtotime("1 $year", time()); $day = date('w', $time); $time += ((7 * $week) + 1 - $day) * 24 * 3600; $r
function getStartAndEndDate($week, $year)
{
$time = strtotime("1 $year", time());
$day = date('w', $time);
$time += ((7 * $week) + 1 - $day) * 24 * 3600;
$return[0] = date('Y-n-j', $time);
$time += 6 * 24 * 3600;
$return[1] = date('Y-n-j', $time);
return $return;
}
如何使用或重写此函数?至于问题中的上述函数,我不知道,但假设一周从周一开始,周日结束,类似的事情可能会起作用
function getFirstandLastDate($year, $month, $week) {
$thisWeek = 1;
for($i = 1; $i < $week; $i++) {
$thisWeek = $thisWeek + 7;
}
$currentDay = date('Y-m-d',mktime(0,0,0,$month,$thisWeek,$year));
$monday = strtotime('monday this week', strtotime($currentDay));
$sunday = strtotime('sunday this week', strtotime($currentDay));
$weekStart = date('d M y', $monday);
$weekEnd = date('d M y', $sunday);
return $weekStart . ' - ' . $weekEnd;
}
echo getFirstandLastDate( 2016, 1, 1 );
函数getFirstandLastDate($year、$month、$week){
$thisWeek=1;
对于($i=1;$i<$week;$i++){
$thisWeek=$thisWeek+7;
}
$currentDay=date('Y-m-d',mktime(0,0,0,$month,$thisWeek,$year));
$monday=strottime('本周星期一',strottime($currentDay));
$sunday=strottime('本周星期日',strottime($currentDay));
$weekStart=日期('d M y',$monday);
$weekEnd=日期('d M y',$sunday);
返回$weekStart.'-'.$weekEnd;
}
echo getFirstandLastDate(2016年1月1日);
我们不处理请求。你试过什么来纠正语法;删除多余的短语;改进了格式。谢谢你,伙计。它真的帮了我:)