我正在尝试在每个月的第一天重置倒计时(例如 2019 年 2 月 1 日)。这是按月计费,但我希望它显示“距下一次帐单还有 x 天”。
我已经设置了一个简单的代码,但我是 PHP 新手,所以我想知道如何每隔 1 次重置它。
<?php
$mysqldate = $_SESSION['u_time'];
$phpdate = strtotime( $mysqldate );
$mysqldate = date( 'd.m.Y', $phpdate );
$oysterContract = date("d.m.Y", strtotime("+3 month", $phpdate));
$dinnerContract = date("d.m.Y", strtotime("+6 month", $phpdate));
$mediumContract = date("d.m.Y", strtotime("+10 month", $phpdate));
$myContract = date("d.m.Y", strtotime("+3 month", $phpdate));
$date = strtotime($myContract);
$remaining = $date - time();
$days_remaining = floor($remaining / 86400);
$hours_remaining = floor(($remaining % 86400) / 3600 );
?>
现在,当你注册时,它会从 30 变为 0,但在 0 之后,它变为 -1、-2 等等。我希望它重置!任何人?
最佳答案
echo (new DateTime('first day of next month'))->diff(new DateTime())->format('%a days');
关于php - 每个新月重置倒计时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54074619/