添加日期时间值


Add datetime Value

我正在寻找在一周内回复天数的最佳方式。首先我需要检查一下有哪一周。然后将一周中的所有日期对应到变量中。

这就是我得到的:

//This Week Variable dates
$this_year = date('Y');
$this_week_no = date('W');
$this_week_mon = new DateTime();
 $this_week_mon->setISODate($this_year,$this_week_no);

我怎么能一天起床?

$this_week_tue = $this_week_mon ++;

您可以使用DateTime::modify():

$this_week_mon->modify('+1 day');

或者接受CCD_ 3对象的CCD_

$this_week_mon->add(new DateInterval('P1D'));

您可以使用DatePeriod():循环浏览一周中的所有日子

$start = new DateTime();
$start->setISODate($this_year,$this_week_no);
$end   = clone $start;
$end->modify('+1 week');
$interval = new DateInterval('P1D');
$period = new DatePeriod($start, $interval, $end);
foreach ($period as $date) {
    echo $date->format('N');
}
$this_week_mon->modify('+1 day');

应将$this_week_mon增加一天。要增加更多,只需使用天数;

$this_week_mon->modify('+27 day');

将增加27天。