用户友好倒计时至午夜

Jam*_*son 2 php time

我有一个在午夜运行的cron作业,它会重置当天的所有用户限制.我希望向用户显示一些内容Your limits reset in 1 hour 14 minutes.基本上倒计时到午夜(服务器时间).

目前我正在使用它来寻找午夜:

strtotime('tomorrow 00:00:00');
Run Code Online (Sandbox Code Playgroud)

它返回午夜翻身的时间戳,但我不知道如何显示用户友好的倒计时.是否有一个PHP库,或者没有库,这很容易吗?

K-G*_*Gun 5

这只是给你左分;

$x = time();
$y = strtotime('tomorrow 00:00:00');
$result = floor(($y - $x) / 60);
Run Code Online (Sandbox Code Playgroud)

但你需要过滤$result;

if ($result < 60) {
    printf("Your limits rest in %d minutes", $result % 60);
} else if ($result >= 60) {
    printf("Your limits rest in %d hours %d minutes", floor($result / 60), $result % 60);
}
Run Code Online (Sandbox Code Playgroud)