Add 30 seconds to the time with PHP

后端 未结 8 2220
旧时难觅i
旧时难觅i 2021-02-05 03:29

How can I add 30 seconds to this time?

$time = date(\"m/d/Y h:i:s a\", time());

I wasn\'t sure how to do it because it is showing lots of diffe

8条回答
  •  自闭症患者
    2021-02-05 04:03

    If you're using php 5.3+, check out the DateTime::add operations or modify, really much easier than this.

    For example:

    $startTime = new DateTime("09:00:00");
    $endTime = new DateTime("19:00:00");
    
    
    while($startTime < $endTime) {
    
    $startTime->modify('+30 minutes'); // can be seconds, hours.. etc
    
    echo $startTime->format('H:i:s')."
    "; break; }

提交回复
热议问题