Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/232.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用php计算超时和超时之间的时间数_Php - Fatal编程技术网

使用php计算超时和超时之间的时间数

使用php计算超时和超时之间的时间数,php,Php,我每天都有用户进出的时间 示例数据: 时间:上午7:00(emp_In) 暂停时间:下午5:00(emp_out) 我想做的只是计算从上午8:00到下午5:00之间的时间,因为用户只安排了上午8:00到下午5:00 下面是我正在使用的示例代码 $result_in_out = strtotime($emp_in) - strtotime($emp_out); $result_hours = abs(floor($result_in_out/3600)); $Considered_Hours =

我每天都有用户进出的时间

示例数据:

时间:上午7:00(emp_In)

暂停时间:下午5:00(emp_out)

我想做的只是计算从上午8:00到下午5:00之间的时间,因为用户只安排了上午8:00到下午5:00

下面是我正在使用的示例代码

$result_in_out = strtotime($emp_in) - strtotime($emp_out);
$result_hours = abs(floor($result_in_out/3600));
$Considered_Hours = $result_hours;

我仍然无法找到并制定一个好的逻辑来以编程方式解释所需的输出,感谢希望它首先对您有用,您应该找到输入的
时间与
上午8:00
之间的差异,然后将差异时间添加到
$emp_IN
中的时间中,然后
输入的时间中减去
超时
,以获得所需的输出

$emp_in = '7:00 am';
// find the difference between time entered and 8:00 am
$diff = '8:00 am' -$emp_in;

// multiply the diffrence time to 3600 to change to second and then add with time in
$emp_in = strtotime($emp_in) + ($diff*3600);

$emp_out = '5:00 pm';

$emp_out = strtotime($emp_out);

$result_in_out = $emp_in - $emp_out;
$result_hours = abs(floor($result_in_out/3600));
echo $result_hours;

有什么问题?那么您想要的输出是什么?代码计算7:00am到5:00pm,但我尝试的是8:00am到5:00pmi如果用户计划从8:00am开始,您能澄清为什么emp_in是从7:00am开始的吗,如果我是对的,你只是想在早上7:00增加+1小时吗?有些情况下,一些用户在早上7:00开始计算时间,但是代码应该只在早上8:00开始计算时间,因为他们被安排在上午8:00。如果用户在早上6:00开始计算时间,那么该代码是否仍将在早上8:00开始计算?不,但是让我为每一个可能的时间进行定制,我想在这种情况下是否应该实施else,但是idk如何处理这种问题。@KingRG如果您的问题没有解决,请告诉我答案。
<?php

$datetime1 = new DateTime('11:00 AM');
$datetime2 = new DateTime('01:00 PM');
$interval = $datetime1->diff($datetime2);
echo $interval->format('%hh %im');
$emp_in = '7:00 am';
// find the difference between time entered and 8:00 am
$diff = '8:00 am' -$emp_in;

// multiply the diffrence time to 3600 to change to second and then add with time in
$emp_in = strtotime($emp_in) + ($diff*3600);

$emp_out = '5:00 pm';

$emp_out = strtotime($emp_out);

$result_in_out = $emp_in - $emp_out;
$result_hours = abs(floor($result_in_out/3600));
echo $result_hours;