如何在php中显示时间结束时的小时和分钟

vecaoik1  于 2021-07-24  发布在  Java
关注(0)|答案(1)|浏览(354)
<span class="m-l-10 text-success text-center pull-right" style="font-size:11px;">                                                           
<? 
    $time_diff=strtotime($row['plannedDate'])-time();
    $minute=($time_diff/60);
    $hour=($minute/60);
    if($minute<=59){
        $follow_time= round($minute). ' minutes left';
    } elseif($hour <= 12){
        $follow_time= round($hour,0). ' hour left';
    }else{
        $follow_time=date("Y-m-d",strtotime($row['plannedDate']));
    }
    echo $follow_time;
?>
</span>

在这里,我编写了一些代码来显示剩余的分钟数和剩余的小时数。
但我只想显示会议剩余的分钟数,并且只想在时间结束时显示小时数和分钟数。
例如,我分配了计划日期,如2020-07-09 12:00:34,它显示28分钟,这是正确的,但如果计划日期时间超过了,如-692分钟,我想同时显示小时和分钟。
怎么做这个?有人能帮我吗?

fd3cxomn

fd3cxomn1#

<span class="m-l-10 text-success text-center pull-right" style="font-size:11px;">                                                           
<?php
    $time_diff=strtotime($row['plannedDate'])-time();
    $minute=($time_diff/60);
    $hour=($minute/60);
    if($minute<=59 && $minute >0){
        $follow_time= round($minute). ' minutes left';
    } elseif($hour <= 12 && $hour > 0){
        $follow_time= round($hour,0). ' hour left';
    }else{
        $hourOver = intdiv(abs($time_diff),3600);
        $minuteOver = intdiv(abs($time_diff)%3600,60);
        $minuteOver = str_pad($minuteOver, 2, "0", STR_PAD_LEFT);
        $follow_time='started ' . $hourOver . ':' . $minuteOver . ' ago';
    }
    echo $follow_time;
?>
</span>

相关问题