date("Y-m-d",strtotime("-1 month")) 获得是上月最后一天

偶尔遇到一个问题,31号时获取上月最后一天时使用了date("Y-m-d",strtotime("-1 month")),结果得到了当月的第一天。因为上个月没有31号。
解决方法很简单,使用

date("Y-m-d", strtotime("last day of -1 month", time()))

解决问题。

你可能感兴趣的:(date("Y-m-d",strtotime("-1 month")) 获得是上月最后一天)