[英]round down to nearest 5 mintues php mysqli
I"m trying to get this time code to round down to the nearest time example if the time listed is 10:28, then i want it to show 10:25 我试图让这个时间代码向下舍入到最近的时间示例,如果列出的时间是10:28,那么我希望它显示10:25
What I have is (the time modify is required) 我有什么(需要修改时间)
<?php
include('../../database/2ndconnection.php');
$sql="SELECT * FROM raid ORDER BY TimeRecord DESC LIMIT 1";
$result=mysqli_query($dbcon,$sql);
while($rows=mysqli_fetch_array($result)){
$dateStr = $rows['TimeRecord'];
$pst = new \DateTime($dateStr);
$pst->modify("-3 hours");
$est = new \DateTime($dateStr);
} ?>
PST: <?php echo $pst->format('H:i'); ?>
<br>EST: <?php echo $est->format('H:i'); ?>
thanks in advance for your help 在此先感谢您的帮助
Insert this: 插入此:
<?php
$currentMinutes = $time->format('i');
$minutesToSubtract = $currentMinutes % 5;
$time = $time->sub(new DateInterval('M' . $minutesToSubtract));
?>
$currentMinutes
will hold the current number of minutes, using %
, you can compute the minutes that need to be subtracted, and afterwards you subtract them through the sub
function $currentMinutes
将保持当前的分钟数,使用%
,您可以计算需要减去的分钟数,然后通过sub
减去它们
It could be integrated into your code as following: 它可以集成到您的代码中,如下所示:
<?php
include('../../database/2ndconnection.php');
$sql="SELECT * FROM raid ORDER BY TimeRecord DESC LIMIT 1";
$result=mysqli_query($dbcon,$sql);
while($rows=mysqli_fetch_array($result)){
$dateStr = $rows['TimeRecord'];
$pst = new \DateTime($dateStr);
$pst->modify("-3 hours");
$est = new \DateTime($dateStr);
}
$currentMinutes = $pst->format('i');
$minutesToSubtract = $currentMinutes % 5;
$pst = $pst->sub(new DateInterval('M' . $minutesToSubtract));
?>
PST: <?php echo $pst->format('H:i'); ?>
<br>EST: <?php echo $est->format('H:i'); ?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.