我在php中有周和年我需要转换日期完成,我是php帮忙的新手
<?php
$weekY = date('Wy' ,strtotime('-1 week'));
print_r(date("Y-m-d",strtotime($weekY)));
?>
结果是1970-01-01
我的数据库中有5113(Wy)如何转换为Wy
<?php
$weekY = date('Wy' ,strtotime(5113));
echo $weekY."<br/>";
?>
结果是0170
我阅读了一些例子,但没有帮助我解决问题
答案 0 :(得分:2)
<?php
$gendate = new DateTime();
$gendate->setISODate(2013,52);//year and week
echo $gendate->format('d-m-Y'); //"prints" 23-12-2013
答案 1 :(得分:0)
感谢所有事情,我对我的问题有了答案
<?php
$y = substr('5213',-2);
$Y = 20..$y;
$W = substr('5213',0,2);
echo "Year + Week: ".$Y." ".$W."<br/>";
$date = new DateTime();
$date->setISODate($Y, $W);
echo "Result: ".$date->format('Y-m-d') . "\n";
?>