* DateInterval
<?php/** * Created by Phpstorm. * USER:MCH * DATE:7/18/18 * time:21:30 * * $datetime = new datetime (' 2018-07-18 21:30:00 ');//+2 weeks$interval = new Dat Einterval (' p2w '); $datetime->add ($interval); Echo $datetime->format (' y-m-d h:i:s '). php_eol;//+ 1month$datetime->add ( new DateInterval (' p1m ')), Echo $datetime->format (' y-m-d h:i:s '). php_eol;// -1month-2weeks$datetime->add ( \dateinterval::createfromdatestring ("1 month-2 weeks"); echo $ Datetime->format (' y-m-d h:i:s '). Php_eol;echo '------------------', php_eol;//start, interval, recurrences$dateperiod = new \dateperiod ( $datetime , \dateinterval::createfromdatestring ('-1 day '), 3), foreach ($datePeriod as $date) { echo $date- Format (' y-m-d '), Php_eol;}
Output
2018-08-01 21:30:00
2018-09-01 21:30:00
2018-07-18 21:30:00
------------------
2018-07-18
2018-07-17
2018-07-16
2018-07-15
* Datetimezone
<?php/** * Created by Phpstorm. * USER:MCH * DATE:7/18/18 * time:21:42 * * $timezone = new Datetimezone (' Asia/tokyo '); $datetime = new \datetime (' 2018-07- 22:42:00 ', $timezone); $datetime->settimezone ( new Datetimezone (' Asia/shanghai ')); Echo $datetime Format (' y-m-d h:i:s '). php_eol;//2018-07-18 21:42:00
* Dateperiod
<?php/** * Created by Phpstorm. * USER:MCH * DATE:7/18/18 * time:21:51 * * $start = new DateTime ()//$interval = new DateInterval (' p2w '); $interval = new DateInterval (' p1d '); $period = new Dateperiod ( $start, $interval, 3, Dateperiod::exclude_start_ DATE), foreach ($period as $nextDateTime) { echo $nextDateTime->format (' y-m-d h:i:s '), Php_eol;} /**2018-07-19 15:54:202018-07-20 15:54:202018-07-21 15:54:20 */
PHP Date-related classes DateInterval Datetimezone dateperiod