我使用下面的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.
谢谢。
答案 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
答案 3 :(得分:1)
然后使用
date("F j, D");for your date function