gpt4 book ai didi

PHP - 计算两个日期时间之间的时间呈现

转载 作者:行者123 更新时间:2023-11-29 19:06:38 24 4
gpt4 key购买 nike

您好,您可以帮助我完成我的项目吗?我在计算两个日期时间之间的渲染时间时遇到问题。具体来说,我的问题是计算员工晚上 10:00 到早上 6:00 之间的夜间差异

e.g1: If the employee time in is 2017-01-01 21:00 (9pm) and the time out is 2017-01-02 05:00 (5am) the output will be: 7hours. 

e.g.2: time in = 2017-01-01 17:00 (5pm) and time out = 2017-01-02 02:00 (2am) the output will be: 4 hours.

e.g.3: timein = 2017-01-01 02:00 (2am) and time out = 2017-01-01 10:00 (10am) the output will be: 4 hours.

如果日志在晚上 10 点到早上 6 点之间通过,计数就会开始

请帮忙提前非常感谢。

最佳答案

这里:

<?php
$output = abs((strtotime("2017-01-01 21:00") - strtotime("2017-01-02 05:00")) / 3600);
echo $output; // Outputs 8

关于PHP - 计算两个日期时间之间的时间呈现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43434677/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com