php中的分钟和天时间操作



我今天必须完成540分钟,即9小时00分钟,我今天的上班时间是上午11:10,所以我可以在下午6点10分之后上班,即我的下班时间

 function convert($time, $format = '%d:%d') {
                settype($time, 'integer');
                if ($time < 1) {
                    return;
                }
                $hours = floor($time / 60);
                $minutes = ($time % 60);
                return sprintf($format, $hours, $minutes);
            }

    $remain_min = 540;
    $remain_time = convert($remain_min, '%02d hours %02d minutes');
    echo 'You have to complete '.$remain_time.' for this week. ';
    $in_timeh =11;
    $in_timem = 10;
    $timeformat = 'AM';
    echo "Your in time" . $in_timeh. ":" . $in_timem . $timeformat . "<br />";

如何计算?

我试过这个,但似乎不太好,请任何人帮助更好的建议

 if($timeformat == "pm"){
    $in_timeh += 12;
    }
    $in_time_minutes = ($in_timeh * 60) + $in_timem;

    $total_minutes_today = $remain_min + $in_time_minutes;
    $total_minutes_today1 = floor($total_minutes_today/60).":".($total_minutes_today%60); 
    $newDateTime = date('h:i A', strtotime($total_minutes_today1));

    echo "You can go after" . $newDateTime;

首先将输入时间和输出时间都设置为字符串,然后将这些值传递给下面的函数,它将返回差值时间。

function timeBetween($start_date,$end_date)   
 {   
    $diff = $end_date-$start_date;   
    $seconds = 0;   
    $hours   = 0;   
    $minutes = 0;   
    if($diff % 86400 <= 0){$days = $diff / 86400;}  // 86,400 seconds in a day   
    if($diff % 86400 > 0)   
    {   
        $rest = ($diff % 86400);   
        $days = ($diff - $rest) / 86400;   
        if($rest % 3600 > 0)   
        {   
            $rest1 = ($rest % 3600);   
            $hours = ($rest - $rest1) / 3600;   
            if($rest1 % 60 > 0)   
            {   
                $rest2 = ($rest1 % 60);   
            $minutes = ($rest1 - $rest2) / 60;   
            $seconds = $rest2;   
            }   
            else{$minutes = $rest1 / 60;}   
        }   
        else{$hours = $rest / 3600;}   
    }   
    if($days > 0){$days = $days.' days, ';}   
    else{$days = false;}   
    if($hours > 0){$hours = $hours.' hours, ';}   
    else{$hours = false;}   
    if($minutes > 0){$minutes = $minutes.' minutes, ';}   
    else{$minutes = false;}   
    $seconds = $seconds.' seconds';
    return $days.''.$hours.''.$minutes.''.$seconds;   
}

尝试这个

$date=date_create("09:00");
date_add($date,date_interval_create_from_date_string("540 minutes"));
echo date_format($date,"H:i");

您可以使用

$add = date("H:i:s", strtotime('+9 hours'));
echo "You can go after".$add;

我希望这对您有所帮助。

<?php
$mystartTime = "11:10:02 AM"; //hour: minute:seconds
$hrs = 60 * 60 * 9;
$mystartTimeSecs = strtotime($mystartTime);
$outTime = date('h:i:s A', $mystartTimeSecs + $hrs);
echo "You can go at " . $outTime;
echo "<br />";
$left = $mystartTimeSecs + $hrs;
$remainingTime = $left - time();
$hours = floor($remainingTime / 3600);
$minutes = floor(($remainingTime / 60) % 60);
$seconds = $remainingTime % 60;
echo "<br />";
echo "Time Left: $hours $minutes $seconds";
echo "<br />";
echo "Time Left: " . date("h:i:s", $remainingTime);

?>

相关内容

  • 没有找到相关文章