-2

我使用下面的 php 从给定的周数和年份获取工作日:

$week_number = 42; 
$year = 2014; 
for($day = 1; $day<=7; $day++)
   {
     echo date('m/d/Y',strtotime($year."W".          $week_number.$day));
  }

输出看起来像这样:

   10/13/2014
   10/14/2014
   10/15/2014
   10/16/2014
   10/17/2014
   10/18/2014
   10/19/2014

我怎样才能让它看起来像这样:

 Oct 13 - Oct 19.

谢谢你。

4

4 回答 4

4
<?php

$week_number = 42; 
$year = 2014; 
echo date('M d',strtotime($year."W".$week_number . 1)) . " - " . date('M d',strtotime($year."W".$week_number . 7)).".";
?>
于 2012-09-24T12:58:18.073 回答
2
$week_number = 42; 
$year = 2014; 

$week_number = ($week_number < 10) ? '0'.$week_number : $week_number;
echo date('M d',strtotime($year.'W'.$week_number.'1')).' - '.date('M d',strtotime($year.'W'.$week_number.'7')).'.';

// remember that $week_number must be prefixed with 0 if week number is lower than 10
于 2012-09-24T12:57:52.940 回答
1

然后使用

date("F j, D");for your date function 
于 2012-09-24T12:58:53.850 回答
1

您可以使用strftime

这是链接http://php.net/manual/en/function.strftime.php

于 2012-09-24T12:57:54.780 回答