• 欢迎访问小杰博客网站
  • 欢迎访问小杰博客网站哦

php的上个月时间的那些坑

php 小杰 2年前 (2021-07-01) 786次浏览 已收录 0个评论

        $last_month = date(‘Ymd’,strtotime(‘-1 month’,strtotime(‘2021-03-01’))); // 前1个月

        $last_month2 = date(‘Ymd’,strtotime(‘-1 month’,strtotime(‘2021-03-30’))); // 前1个月

        $last_month3 = date(‘Ymd’,strtotime(‘-1 month’,strtotime(‘2021-08-31’))); // 前1个月

        $last_month4 = date(‘Ymd’,strtotime(‘-1 month’,strtotime(‘2021-01-02’))); // 前1个月

        $last_month5 = date(‘Ymd’,strtotime(‘-1 month’,strtotime(‘2021-09-30’))); // 前1个月

        $last_month6 = date(‘Ymd’,strtotime(‘-1 month’,strtotime(‘2021-07-31’))); // 前1个月

        

        

        \Log::info(‘test_last_month:’.$last_month.‘ last_month2:’.$last_month2.‘ last_month3:’.$last_month3.‘ last_month4:’.$last_month4.‘ last_month5:’.$last_month5.‘ last_month6:’.$last_month6);

        

local.INFO: test_last_month:20210201 last_month2:20210302 last_month3:20210731 last_month4:20201202 last_month5:20210830 last_month6:20210701 

 

结论:用1号的字符串再-1 month就没事了


小杰博客 , 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:php的上个月时间的那些坑
喜欢 (0)
发表我的评论
取消评论
表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址