2013-08-24 113 views
0

經過一個多小時的努力和努力,我想在這裏問一下。從DateTime獲取日期對象

試圖與周等東西在PHP中,我從你的網站這讓: Get all Work Days in a Week for a given date

尼斯和會爲我工作的罰款。

但是......我得不到的東西,嘗試並試圖,該出這部分數據:[date] => 2013-08-12 00:00:00

Array 
(
    [0] => DateTime Object 
     (
      [date] => 2013-08-12 00:00:00 
      [timezone_type] => 3 
      [timezone] => Europe/Amsterdam 
     ) 

如何獲得該日期出數組的? 請幫助我,提前感謝您的幫助!

回答

0

使用DateTime::format()

$dateTime = new DateTime('2013-08-12 00:00:00'); 
echo $datetime->format('Y-m-d'); // produces 2013-08-12 
0
$firstMondayThisWeek= new DateTime('2013-08-12'); 
$firstMondayThisWeek->modify('tomorrow'); 
$firstMondayThisWeek->modify('last Monday'); 

$nextFiveWeekDays = new DatePeriod(
    $firstMondayThisWeek, 
    DateInterval::createFromDateString('+1 weekdays'), 
    4 
); 

$dateTimes = iterator_to_array($nextFiveWeekDays); 
foreach ($dateTimes as $dateTime) { 
    echo $dateTime->format('Y-m-d H:i:s'); 
} 
+0

這個工作很適合我,謝謝 – Jeroen