如何获取一个星期中的星期一的日期以及一年中的年数?
例如,如果年份为2020,年份中的星期数为01,则预期结果为2019-12-30
答案 0 :(得分:3)
希望这就是您想要的:)
<?php
$week_number = '06';
$year_number = '2020';
function getStartAndEndDate($week, $year) {
$date = new DateTime();
$date->setISODate($year, $week);
for ($i=0; $i < 7; $i++) {
$array[$i] = $date->format('Y-m-d');
$date->modify('+1 days');
}
return $array;
}
$week_array = getStartAndEndDate($week_number,$year_number);
echo $week_array[0]; // 0 = monday, 1 = tuesday, and so on :)
?>
答案 1 :(得分:0)
<?php
$week = 1;
$year = 2020;
$dateTime = date_create(sprintf("%04dW%02d",$year,$week)); //always a monday
echo $dateTime->format('Y-m-d'); //2019-12-30