Calculate the difference between date/times in PHP

前端 未结 5 1411
名媛妹妹
名媛妹妹 2020-12-11 19:17

I have a Date object ( from Pear) and want to subtract another Date object to get the time difference in seconds.

I have tried a few things but the first just gave

5条回答
  •  生来不讨喜
    2020-12-11 19:40

    To do it without pear, to find the seconds 'till 17:00 you can do:

    $current_time = mktime (); 
    $target_time = strtotime (date ('Y-m-d'. ' 17:00:00')); 
    $timediff = $target_time - $current_time;
    

    Not tested it, but it should do what you need.

提交回复
热议问题