需要计算PHP中从当前日期到每个月27日的天数
在下面的代码中,它可以正确计算当前月份,但是如果当前日期是28日,则应该计算下个月。
$year = date("y");
$month = date("m");
$day = '27';
$current_date = new DateTime(date('Y-m-d'), new DateTimeZone('Asia/Dhaka'));
$end_date = new DateTime("$year-$month-$day", new DateTimeZone('Asia/Dhaka'));
$interval = $current_date->diff($end_date);
echo $interval->format('%a day(s)');
最佳答案
我写了这个脚本很快,因为我还没有时间对其进行测试。
编辑:
$day = 27;
$today = date('d');
if($today < $day){
$math = $day - $today;
echo "There are " . $math . " days left until the 27th.";
} else {
$diff = date('t') - $today;
$math = $diff + $day;
echo "There are " . $math . " days left until the 27th of the next month.";
}
关于php - 如何计算每个月在PHP中的天数,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/44692047/