在PHP中获得下个月的最后一天? [英] get last day of the next month in php?
本文介绍了在PHP中获得下个月的最后一天?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个如下所示的php代码,我在其中尝试检索下个月的最后一天.
I have a php code as shown below in which I am trying to retrieve the last day of next month.
<?php
date_default_timezone_set('America/Toronto');
echo date('l jS \of F Y h:i:s A');
$next_month_last_day = date('t', strtotime('next month')); // last day of the next month
print_r("\n");
print_r($next_month_last_day); // Line A
?>
问题陈述:
我想知道我在上面的php代码中犯了什么错误,因为 A行上的代码显示31.应该打印30,因为最后一个下个月的(4月)是30.
I am wondering what mistake I have done in the php code above because the code at Line A prints 31. It should be printing 30 because the last day of next month (April) is 30.
推荐答案
只需使用
date('d', strtotime('last day of +1 month'));
这篇关于在PHP中获得下个月的最后一天?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文