PHP 中减去时间
我已经寻找答案几个小时了,但找不到。
我正在编写一个简单的脚本
。用户设置工作开始和结束时间。例如,某人从 8:00 工作到 16:00。 我怎样才能减去这个时间来看看这个人已经工作了多长时间?
我正在尝试 strtotime();
但没有成功......
I have been looking for an answer for a few hours now, but I can't find one.
I'm writing a simple script
. The user sets their work start and end time. So, for example, somebody is working from 8:00 to 16:00.
How can I subtract this time to see how long the person has been working?
I was experimenting with strtotime();
but without success...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
更好一点的是:
这将为您提供小时数的差异。
A bit nicer is the following:
That will give you the difference in hours.
如果您获得有效的日期字符串,则可以使用此:
这将为您提供一个人的工作时间。
If you get valid date strings, you can use this:
This will give you the hours a person has been working.
另一种解决方案是检查 Unix 时间戳整数值差异(以秒为单位)。
如果您的原始日期以 Unix 时间戳格式存储,则此解决方案会更好。
Another solution would be to go through the Unix-timestamp integer value difference (in seconds).
This solution would be a better one if your original dates are stored in Unix-timestamp format.