Php strtotime 函数 -1 month 的参数坑

版权声明:潘广宇博客, https://blog.csdn.net/panguangyuu/article/details/88407386
<?php

// 现在想要获取 2018-05-31 的上一个月的最后一天

var_dump(date("Y-m-d", strtotime("-1 month"), strtotime("2018-05-31"))));

// 返回结果是 2018-05-01,因为4月没有31号。

正确的方法:

var_dump(date("Y-m-d", strtotime("last day of -1 month"), strtotime("2018-05-31"))));

猜你喜欢

转载自blog.csdn.net/panguangyuu/article/details/88407386
今日推荐