strtotime function for hours more than 24

前端 未结 2 715
悲哀的现实
悲哀的现实 2021-01-17 02:20

Hello I am trying to compare a time during with Hours:Minutes:Seconds format using strtotime function but there is a probleme if Hours is more than 24

PHP Code:

相关标签:
2条回答
  • 2021-01-17 03:02

    The way I'd solve that would be with mktime:

    function getTimeFromString($time){
        $time = explode(':', $time);
        return mktime($time[0], $time[1], $time[2]);
    }
    
    if(getTimeFromString($time_duration_1) > getTimeFromString($time_duration_2)){
    
    0 讨论(0)
  • 2021-01-17 03:16

    Make a function to calculate your hours, minutes and seconds:

    function formatHours($time){
        $date = explode(':', $time);
        return ($date[0]*60*60)+($date[1]*60)+$date[2];
    }
    
    if(formatHours($time_duration_1) > formatHours($time_duration_2)){
    // ......
    
    0 讨论(0)
提交回复
热议问题