Get interval seconds between two datetime in PHP?

后端 未结 8 1118
孤街浪徒
孤街浪徒 2021-01-31 07:08

2009-10-05 18:11:08

2009-10-05 18:07:13

This should generate 235,how to do it ?

8条回答
  •  时光说笑
    2021-01-31 07:32

    With DateTime objects, you can do it like this:

    $date = new DateTime( '2009-10-05 18:07:13' );
    $date2 = new DateTime( '2009-10-05 18:11:08' );
    
    $diffInSeconds = $date2->getTimestamp() - $date->getTimestamp();
    

提交回复
热议问题