是否可以使用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