get difference in time in HH:MM format php

后端 未结 2 1760
灰色年华
灰色年华 2020-12-20 21:44

how can i get this to output

HH:MM format?

 $to_time = strtotime(\"2008-12-13 10:42:00\");  <--AM
 $from_time = strtotime(\"2008-12-14 8:21:00\")         


        
2条回答
  •  盖世英雄少女心
    2020-12-20 22:13

    First of all you need to include AM and PM in your date strings, otherwise 2008-12-14 8:21:00 will be interpreted as 8:21 AM

    Now the difference between two dates is 2019 that is 33h:19m, you cant' have t with standard date formats, since they support only 24h clock. You should keep $stat as integer, and display it with sprintf like like this:

    echo sprintf('%02dh:%02dm', $stat/60, $stat%60);
    

提交回复
热议问题