获取一小时内前8个季度、一小时前
我想做的是显示一小时内、一小时前的最后 8 个季度。
我已经有了这个:
<?php
echo date('d-m-Y H:i:s', strtotime('-1 hour'));
?>
例如:
现在是 14:46(下午 2:46),所以我想要的是:
13:45
13:30
13:15
13:00
12:45
12:30
12:15
12:00
我怎样才能得到它?
What i want to do, is display the last 8 quarters in an hour, one hour ago.
I already have this:
<?php
echo date('d-m-Y H:i:s', strtotime('-1 hour'));
?>
For example:
Its now 14:46 (2:46 PM), so what i want, is this:
13:45
13:30
13:15
13:00
12:45
12:30
12:15
12:00
How can i get that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
现在可以工作,但我还没有进一步测试。
当地时间:15:06
输出:
Works right now, but I have not tested any further.
Local time: 15:06
Output:
要解决这个问题,您需要弄清楚上个季度是什么时候。然后从那里返回就很容易了。我会这样做:
尝试找出我的代码在做什么。特别是学习如何使用 modulo 运算符,因为它对于大量数字问题非常有用!
To solve this problem, you need to figure out when the last quarter was. Then it's as easy as going back from there. Here's how I would do it:
Try to figure out what my code is doing. Especially learn how to use the modulo operator since it's very useful for a large set of numeric problems!
或者另一种方法来做到这一点,只是我快速组合起来的东西:
输出:
Or another way to do it, just something i quickly put together:
Output:
我建议它不需要那么多代码来完成您需要的操作:
I suggest it doesn't need anywhere near so much code to do what you need: