我是靠谱客的博主 小巧未来,这篇文章主要介绍PHP strtotime 的 BUG,现在分享给大家,希望可以做个参考。

strtotime('+1 month'),strtotime('-1 month') 碰到一个月中有28, 31天的就会有问题,比如 strtotime('+1 month', strtotime('2019-10-31')) 就会跳到 12月份去,而不是11月份;

从 PHP5.3 开始呢,date 新增了一系列修正短语,来明确这个问题,那就是”first day of” 和 “last day of” 解决了

复制代码
1
2
strtotime('last day of -1 month') strtotime("first day of +1 month")

可以智能的判断一个月份的最后一天是几号(28/29/30/31)

复制代码
1
2
3
4
5
6
7
8
9
10
echo date("Y-m-d", strtotime("2017-02 first day of")).'<br>'; //2017-02-01 echo date("Y-m-d", strtotime("2017-02 last day of")).'<br>'; //2017-02-28 echo date("Y-m-d", strtotime("2017-05 last day of")).'<br>'; //2017-05-31 echo date("Y-m-d", strtotime("first day of")).'<br>'; //2021-06-01 echo date("Y-m-d", strtotime("last day of")).'<br>'; //2021-06-30

最后

以上就是小巧未来最近收集整理的关于PHP strtotime 的 BUG的全部内容,更多相关PHP内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(57)

评论列表共有 0 条评论

立即
投稿
返回
顶部