如何显示给定周数的格式化工作日

时间:2012-09-24 12:54:28

标签: php strtotime

我使用下面的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 个答案:

答案 0 :(得分: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)).".";
?>

答案 1 :(得分: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

答案 2 :(得分:1)

您可以使用strftime

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

答案 3 :(得分:1)

然后使用

date("F j, D");for your date function