Get interval seconds between two datetime in PHP?

后端 未结 8 1232
孤街浪徒
孤街浪徒 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:28

    A simple and exact solution (exemplifying Nilz11's comment):

    $hiDate = new DateTime("2310-05-22 08:33:26");
    $loDate = new DateTime("1910-11-03 13:00:01");
    $diff = $hiDate->diff($loDate);
    $secs = ((($diff->format("%a") * 24) + $diff->format("%H")) * 60 + 
       $diff->format("%i")) * 60 + $diff->format("%s");
    

提交回复
热议问题