PHP time intervals

后端 未结 1 1023
夕颜
夕颜 2021-01-28 14:42

I\'m looking for a solution to something which seems like it should be pretty simple, but it doesn\'t seem that I can find any good answers on here, and I can\'t seem to get it

相关标签:
1条回答
  • 2021-01-28 14:56

    Off of the top of my head. You can tweak as necessary.

    $start    = new DateTime('2013-08-14 09:00:00');
    $end      = new DateTime('2013-08-14 17:00:00');
    $interval = new DateInterval('PT30M');
    $period   = new DatePeriod($start, $interval, $end);
    
    foreach ($period as $dt)
    {
        // do something
        echo $dt->format('H:iA');
    }
    

    Links

    • DateTime
    • DateInterval
    • DatePeriod
    0 讨论(0)
提交回复
热议问题