PHP - 从时差中排除所有非营业时间/天 [英] PHP - Exclude all non-business hours / days from time difference

查看:24
本文介绍了PHP - 从时差中排除所有非营业时间/天的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一张表格,显示了自提出工作以来的时间.

I have a table which shows the time since a job was raised.

// These are unix epoch times...
$raised = 1360947684;
$now = 1361192598;
$difference = 244914;

$difference 需要排除工作时间以外的任何时间(例如,9-5 和周末).

$difference needs to exclude any time outside of business hours (ex, 9-5 and weekends).

我该如何解决这个问题?

How could I tackle this?

推荐答案

你要做的就是3个数字.

The thing you have to do are 3 in numbers.

  1. 您取开始日期并计算这一天的休息时间(如果是工作日)
  2. 您选择结束日期并计算这一天的时间,然后
  3. 您将两者之间的天数乘以您的营业时间(只是那些,即营业日)

你就完成了.

找到一个附加的小类,它可以做这些事情.注意没有错误处理、时区设置、夏令时……

Find a little class attached, which does those things. Be aware that there is no error handling, time zone settings, daylight saving time, ...

输入:

  • 开始日期
  • 结束日期

输出:

  • 以秒为单位的时间差

可调常数:

  • 营业时间
  • 非工作日

这篇关于PHP - 从时差中排除所有非营业时间/天的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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