第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會有你想問的

PHP - 無法從時(shí)間中刪除分鐘

PHP - 無法從時(shí)間中刪除分鐘

PHP
蕭十郎 2023-04-28 15:58:49
我有 3 個(gè)變量存儲時(shí)間,它們?nèi)缦拢?start_time_name = 開始時(shí)間$end_time_name = 結(jié)束時(shí)間$total_break_name = 休息時(shí)間我可以計(jì)算開始時(shí)間和結(jié)束時(shí)間之間的差異,盡管它從不考慮中斷(即使中斷變量帶回正確的值)$total_hours_work_cal = ($end_time_name - $total_break_name);對此的計(jì)算是;結(jié)束時(shí)間 = 10:00開始時(shí)間 = 05:00休息時(shí)間 = 00:30但它只返回 05:00 而不是預(yù)期的 04:30有任何想法嗎?我在Stack Overflow上嘗試了很多用戶建議的方法,但都無濟(jì)于事。**編輯*編輯以包含更多代碼;$start_time_name = $_POST['start_time_name'];  $end_time_name = $_POST['end_time_name'];  $total_break_name = $_POST['total_break_name'];  $total_hours_work_cal = ($end_time_name - $total_break_name - $start_time_name)   * 60 * 60;  echo "BEFORE CONVERSION" . $total_hours_work_cal;  $total_hours_work_cal = gmdate("H:i:s", $total_hours_work_cal);  echo "AFTER CONVERSION" . $total_hours_work_cal;
查看完整描述

3 回答

?
慕田峪7331174

TA貢獻(xiàn)1828條經(jīng)驗(yàn) 獲得超13個(gè)贊

function hoursandmins($time, $format = '%02d:%02d'){

    if ($time < 1) {

        return;

    }

    $hours = floor($time / 60);

    $minutes = ($time % 60);

    return sprintf($format, $hours, $minutes);

}


$start_time_name    = "05:00";

$end_time_name  = "10:00";

$total_break_name   = "30"; //in minutes


$start_time_name = strtotime($start_time_name);

$end_time_name   = strtotime($end_time_name);

$total_break_name = (int) $total_break_name * 60; //convert into seconds


$total_hours_work_cal = $end_time_name - $total_break_name - $start_time_name; //total time will be in seconds

$total_hours_work_cal = $total_hours_work_cal / 60; //converted into minutes;


$total_hours_work_cal = hoursandmins($total_hours_work_cal); //convert into hours and minutes

echo $total_hours_work_cal;


查看完整回答
反對 回復(fù) 2023-04-28
?
哈士奇WWW

TA貢獻(xiàn)1799條經(jīng)驗(yàn) 獲得超6個(gè)贊

/* justfor testing purpose to have input */


$_POST['start_time_name'] = "05:00";

$_POST['total_break_name'] = "00:30";

$_POST['end_time_name'] = "10:00";



$start_time_name = $_POST['start_time_name'];

$end_time_name = $_POST['end_time_name'];

$total_break_name = $_POST['total_break_name'];


$end_time = mktime(explode(":",$end_time_name)[0],explode(":",$end_time_name)[1]);

$start_time = mktime(explode(":",$start_time_name)[0],explode(":",$start_time_name)[1]);

$total_break = mktime(explode(":",$total_break_name)[0],explode(":",$total_break_name)[1]);


$diff = $end_time + $total_break - $start_time;


$total_hours_work_cal = date("H:i",$diff);


echo "TOTAL HOURS OF WORK : " . $total_hours_work_cal;


// TOTAL HOURS OF WORK : 05:30


查看完整回答
反對 回復(fù) 2023-04-28
?
守著一只汪

TA貢獻(xiàn)1872條經(jīng)驗(yàn) 獲得超4個(gè)贊

<?php

/*


$total_hours_work_cal = ($end_time_name - $total_break_name);


The calculation for this would be;


    End time = 10:00

    Start Time = 05:00

    Break Time = 00:30

*/


$start = new \DateTime('05:00:00');

$end = new \DateTime('10:00:00');

$break = new \DateInterval('PT30M');


$beginEndInterval = $end->diff($start);


$total = new \DateTime('00:00');

$totalComp = new \DateTime('00:00');

$total->add($beginEndInterval);

$total->add($break);

echo $totalComp->diff($total)->format('%H:%I'); // 04:30


查看完整回答
反對 回復(fù) 2023-04-28
  • 3 回答
  • 0 關(guān)注
  • 173 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號