Add 30 seconds to the time with PHP

后端 未结 8 2039
旧时难觅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:08

    You could solve this with a bit different perspective. First, you can create a current datetime object. Then, you create a future datetime which is 30 seconds later then your given datetime. So it boils down to the following:

    (new Future(
        new Now(),
        new NSeconds(30)
    ))
        ->value();
    

    If you want to output in a specific format you've mentioned, it can be achieved with

    (new ISO8601Formatted(
        new Future(
            new Now(),
            new NSeconds(30)
        ),
        'm/d/Y h:i:s a'
    ))
        ->value()
    

提交回复
热议问题