gpt4 book ai didi

php - 将 15 分钟添加到当前时间并捕捉到 15 分钟的间隔

转载 作者:可可西里 更新时间:2023-11-01 13:35:47 25 4
gpt4 key购买 nike

我需要将当前时间加 15 分钟。例如:现在是20:48,需要加上15分钟,所以现在是21:03,但是我需要设置21:15,也就是,它应该是 15,30,45,00 的倍数。帮助帮助/指导会有很好的帮助。

<?php
$current_date_time = date('d/m/Y H:i:s');
$current_date = date("d/m/Y H:i", strtotime($current_date_time."+15 minutes"));
echo $current_date;exit;

最佳答案

这是一个简单的例子

//what time is it?
$t=time();

//how long is our interval?
$interval=15*60;

//we can calculate when the last interval started by subtracting $t % $interval
$last = $t - $t % $interval;

//so now we know when the next interval will start...
$next = $last + $interval;

echo "Next interval at ".strftime('%H:%M:%S', $next)."\n";

您看起来可能想将 2*$interval 添加到最后一个间隔,但您应该能够调整它以适合您。

关于php - 将 15 分钟添加到当前时间并捕捉到 15 分钟的间隔,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17022361/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com