-3

谁能告诉我为什么当日期 >= 2013-01-06 时以下失败

太奇怪了,当日期在这个日期之后时,脚本可以完美运行,但之前的任何东西都可以,我得到了白屏死机!

<?php 

use Carbon\Carbon;

$startDate    = Carbon::createFromFormat('Y-m-d', '2013-01-06');
$current_week = Carbon::now()->timestamp;

/*
$startDate    = strtotime('2013-01-06');
$current_week = strtotime(date('Y-m-d'));
*/

$weeks        = array();
$w            = 0;

while($startDate < $current_week){
    $weeks[$w] = array(
        'monday' => $startDate->startofWeek()->format('d/m/Y'), 
        'sunday' => $startDate->endofWeek()->format('d/m/Y')
    );
    $w++;
    $startDate = $startDate->addDays(1); // Move it on to the following week
}

var_dump($weeks);

?>

请问有人可以帮我吗?!

4

1 回答 1

1

这个 ?我们比较timestamp和timestamp,而不是datetime对象和timestamp,我不知道Carbon类,这里$startDate->timestamp必须换成carbon datetime对象转unix timestamp的方法。

<?php 

use Carbon\Carbon;

$startDate    = Carbon::createFromFormat('Y-m-d', '2013-01-06');
$startDateTimestamp = $startDate->timestamp;
$current_week = Carbon::now()->timestamp;

/*
$startDate    = strtotime('2013-01-06');
$current_week = strtotime(date('Y-m-d'));
*/

$weeks        = array();
$w            = 0;

while($startDateTimestamp < $current_week){
    $weeks[$w] = array(
        'monday' => $startDate->startofWeek()->format('d/m/Y'), 
        'sunday' => $startDate->endofWeek()->format('d/m/Y')
    );
    $w++;
    $startDate = $startDate->addDays(7); // Move it on to the following week
    $startDateTimestamp = $startDate->timestamp;
}

var_dump($weeks);

?>
于 2013-10-27T14:29:04.027 回答