根据两个给定时间计算时间长度 [英] Calculate time length based on two given times

查看:349
本文介绍了根据两个给定时间计算时间长度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

需要帮助来计算$work_in_daytime$work_in_nighttime.

$nightStart = '22:00';
$nightEnd = '07:00';

$workers = array(
    '0' => array(
        'name'  => 'Lyons',
        'start' => '15:15',
        'end'   => '23:45'
    ),

    '1' => array(
        'name'  => 'Santos',
        'start' => '10:00',
        'end'   => '22:00'
    ),

    '2' => array(
        'name'  => 'Montgomery',
        'start' => '22:30',
        'end'   => '08:00'
    )
); 


foreach ($workers as $worker) {
    $length_of_work = abs(strtotime($worker['start']) - strtotime($worker['end'])) / 3600;
    $work_in_daytime = '';
    $work_in_nighttime = '';
}

感谢您的帮助.

推荐答案

  <?php
    $start_time = strtotime("2017-09-01 10:42:00");
    $end_time = strtotime("2017-09-02 10:21:00");
    //Divide seconds by 60 to get minutes or whatever is appropriate and round off
    echo $difference = round(abs($to_time - $from_time) / 60,2). " minutes";
?>

这篇关于根据两个给定时间计算时间长度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆