上个月的最后几天
在 PHP 中,我使用 此处 中的代码生成日历。我已将其与 Basecamp 连接起来,并成功计算每天的工作时间,并将一周和一个月的工作时间相加。为了正确计算加班时间,我需要整周的小时数,即使它跨越月末/月初。
经过几个小时的尝试,我无法计算出标有“?”的日期的日期在上图中。
我无法摆脱这样的感觉:我在这里错过了一些明显的东西,但一直无法弄清楚。非常感谢任何帮助,谢谢。
In PHP, I'm generating a calendar with code from here. I've connected it with Basecamp and am successfully calculating the hours worked each day and sum them for the week and month. To properly calculate overtime, I need the hours from the whole week, even when it spans the end/beginning of a month.
After several hours of trying, I haven't been able to calculate the dates of the days marked with '?' in the above image.
I can't escape the feeling that I'm missing something obvious here, but haven't been able to figure it out. Any help much appreciated, thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用
mktime()
并设置小于1
的日期参数:0
表示最后一天,-1< /code> 代表最后一天的前一天,等等。
这给你一个 UNIX 时间戳,你可以用它来找出工作日,然后 - 直到你到达星期日/星期一(无论你使用哪个星期开始) - 减去 -86400 或再次调用
mktime()
,并将天数减 1。示例:
You can use
mktime()
and set a day argument which is less than1
:0
for the last day,-1
for the day before the last day, etc.That gives you a UNIX timestamp you can use to find out the weekday and then - until you've reached Sunday/Monday (whatever week start you use) - subtract -86400 or call
mktime()
again with the day reduced by 1.Example: