是否可以使用PHP的Relative Date Time format获取一周的第一个/最后一个日期?获取本周的第一个/最后一个日期
我试图做的事:
date_default_timezone_set('Europe/Amsterdam');
$date = new DateTime();
$date->modify('first day of this week'); // to get the current week's first date
echo $date->format('Y-m-d'); // outputs 2011-12-19
$date->modify('first day of week 50'); // to get the first date of any week by weeknumber
echo $date->format('Y-m-d'); // outputs 2011-12-18
$date->modify('last day of this week'); // to get the current week's last date
echo $date->format('Y-m-d'); // outputs 2011-12-17
$date->modify('last day of week 50'); // to get the last date of any week by weeknumber
echo $date->format('Y-m-d'); // outputs 2011-12-18
正如你可以see它不输出正确的日期。
根据the docs这应该是可能的,如果我是正确的。
我是否在做可怕的错误?
编辑
我需要使用PHP的日期时间在遥远的未来日期。
UPDATE
现在只得到陌生人。我已经做了更多的测试。
的Windows PHP 5.3.3
2011-12-01
Warning: DateTime::modify() [datetime.modify]: Failed to parse time string (first day of week 50) at position 13 (w): The timezone could not be found in the database in C:\Users\Gerrie\Desktop\ph\Websites\Charts\www.charts.com\public\index.php on line 9
2011-12-01
2011-11-30
Warning: DateTime::modify() [datetime.modify]: Failed to parse time string (last day of week 50) at position 12 (w): The timezone could not be found in the database in C:\Users\Gerrie\Desktop\ph\Websites\Charts\www.charts.com\public\index.php on line 15
2011-11-30
的Linux 5.3.8
2011-12-01
2011-12-01
2011-11-30
2011-11-30
如果星期日或星期一是星期几的第一天,这种喜欢取决于语言环境吗? – mario 2011-12-16 23:41:58
@mario:我不知道你告诉我。无论哪种方式,前两个应该输出相同的东西。最后两名恕我直言,同样如此。无论是星期天/星期一开始 – PeeHaa 2011-12-16 23:43:36