如何按月,年和周数计算一周的开始和结束日期?年份是4位整数,例如2016;月份是整数,范围是1-12;周是1-5范围内的整数。
我已经有了这个代码块:
static_assert(T(double(T type))==type);
如何使用或重写此功能?
答案 0 :(得分:2)
关于你在上面的问题,我不知道,但假设星期一开始,周日结束,这样的事可能会有效
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 );