一分钟到最近四分之一小时 [英] Round minute down to nearest quarter hour
本文介绍了一分钟到最近四分之一小时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要在PHP中最近四分之一小时的时间。时间正在从datetime列从MySQL数据库中拉出,格式如下:$ code> 2010-03-18 10:50:00 。
I need to round times down to the nearest quarter hour in PHP. The times are being pulled from a MySQL database from a datetime column and formatted like 2010-03-18 10:50:00
.
示例:
- 10:50需要为10:45
- 1 :12需要1:00
- 3:28需要是3:15
- 等。
- 10:50 needs to be 10:45
- 1:12 needs to be 1:00
- 3:28 needs to be 3:15
- etc.
我假设 floor()
涉及但不知道该怎么做。
I'm assuming floor()
is involved but not sure how to go about it.
谢谢
推荐答案
你的全部功能将是这样的...
Your full function would be something like this...
function roundToQuarterHour($timestring) {
$minutes = date('i', strtotime($timestring));
return $minutes - ($minutes % 15);
}
这篇关于一分钟到最近四分之一小时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文