ThinkChat🤖让你学习和工作更高效,注册即送10W Token,即刻开启你的AI之旅 广告
> DatePeriod 类表示一个时间周期。 > DatePeriod 类继承自Traversable预定义接口 ``` DatePeriod implements Traversable { /* 常量 */ const integer EXCLUDE_START_DATE = 1 ;//在构造函数中使用,表示不包含开始时间。 /* 属性 */ public integer $recurrences ; public boolean $include_start_date ; public DateTimeInterface $start ; public DateTimeInterface $current ; public DateTimeInterface $end ; public DateInterval $interval ; /* 方法 */ public __construct ( DateTimeInterface $start , DateInterval $interval , int $recurrences [, int $options ] ) public __construct ( DateTimeInterface $start , DateInterval $interval , DateTimeInterface $end [, int $options ] ) public __construct ( string $isostr [, int $options ] ) public getDateInterval ( void ) : DateInterval public getEndDate ( void ) : DateTimeInterface public getRecurrences ( void ) : int public getStartDate ( void ) : DateTimeInterface } ``` ``` // 获取两个时间内的所有日期实例 $begin = new DateTime('2012-08-01'); $end = new DateTime( '2012-08-31' ); $interval = new DateInterval('P2D'); // 时间间隔为2天 $daterange = new DatePeriod($begin, $interval,$end,DatePeriod::EXCLUDE_START_DATE ); foreach($daterange as $date){ echo $date->format("Ymd") . "<br>"; } ```