-3

根据今年的周数,我无法弄清楚从星期一获取日期的代码。

有人可以帮我处理这段代码吗?

谢谢。

4

3 回答 3

2

这将提供今年某一周的星期一:

$thisYear = date('Y');
$weekNum = 40;

$date = date('Y-m-d', strtotime("$thisYear-W$weekNum-1"));  // Outputs 2013-09-30
于 2013-09-03T18:54:34.477 回答
1

使用DateTime类:

$dt = new DateTime;
$dt->setISODate($year, $week);
echo $dt->format('Y-m-d');

demo

于 2013-09-04T08:23:41.650 回答
-1

我有这个(我不确定我或其他人是否是原作者)但试一试:

  $week = 34; //Enter your week here.

  $week = mktime( 0, 0, 0, 1, 1,  2013 ) + ( $week * 7 * 24 * 60 * 60 ); 

  $monday = $week - 86400 * ( date( 'N', $week ) - 1 );
  $monday = date( 'Y-m-d', $monday );

  echo $monday;
于 2013-09-03T18:52:42.730 回答