2009-11-06 136 views
3

我想要一个星期的第一天说我有第45周。现在我想有本周的第一个星期日的日期。 任何人都可以告诉我如何去做这件事?一周的第一天

谢谢

回答

4

张望了一下搜索,最建议是:

$year = "2009"; // date("Y"); 
$week = "45"; // date("W"); 

$firstDayOfWeek = strtotime($year."W".str_pad($week,2,"0",STR_PAD_LEFT)); 

print("The first day of week ".$week." of ".$year." is ".date("D, d-m-Y",$firstDayOfWeek)); 

这基本上可以归结为让的strtotime做的工作适合你。你填写“2009W45”,它会为你检索日期。 这里的缺点是,本周需要采用2位数字格式。因此,第1周需要为01,因此str_pad将其填充为零。

+0

'2009W45' =>我只需要这种格式!谢谢! :d – 2015-08-07 07:07:50

1

你应该strtotimedate功能

$next_sunday = strtotime('next sunday'); 
$next_week = strtotime('+1 week'); 
$next_sunday_of_next_week = strtotime('next sunday', $next_week); 

希望一些代码,这有助于

0

如果您有月,日和年:

$timestamp = mktime(0, 0, 0, $month, $day, $year); 
echo date('c', $timestamp) = mktime(0, 0, 0, $month, date('d', $timestamp)-date('w', $timestamp), $year); 

你也可以做到这样,如果你有时间戳:

echo $date('c', mktime(0, 0, 0, $month, date('d', $timestamp)-date('w', $timestamp), $year)); 

来源:http://pinoytech.org/blog/post/get-the-first-day-of-the-week-with-an-exact-date

0

date($str_format, strtotime($year."W".$week."1"))

哪里$str_format是根据PHP date()function输出甲..我使用'M d Y'

+0

如果您将星期一作为第一周,则适用。 – 2009-11-06 06:15:10

-1

如果您能向我们提供更多的细节,您希望以何种语言达到此目的,我们只能提供帮助,明确指出这需要在任何语言,脚本或数据库中完成?

+1

问题标签为php。 – notJim 2009-11-06 06:16:56