根据ISO标准,2013年第52周,周六开始,从2013-12-28开始,到2014-01-03(包括)结束。
代码:
echo date('Y-m-d', strtotime("2013-W52-6"));//prints 2013-12-28
现在,我正试图用PHP弄清楚逆。如果我的日期是2014-01-03,如果星期六星期开始,如何知道该日期的ISO周数?
答案 0 :(得分:0)
使用DateTime类:
答案 1 :(得分:0)
$date = "2013-12-28";
$dayofyear = date("z", $date);
$week = floor($dayofyear / 7) + 1;
// I assume week starts with Monday (I think as ISO does?)
// so only weeks that start on sunday will count as "week 0" instead of "week 1"
// I could be wildly wrong, adjust according to your needs
$first_day = date("w", date("Y", $date) . "-01-01");
if ($first_day == 6)
--$week;
echo $week;
答案 2 :(得分:-1)
$date = "2013-12-28";
$date_array = explode("-", $date);
$date = mktime(0, 0, 0, $date_array[1], $date_array[2], $date_array[0]);
$week_number = date('W', $date);
echo $week_number;
像这样。