首页 > Web开发 > 详细

php获取下个月的今天

时间:2016-04-25 19:47:06      阅读:235      评论:0      收藏:0      [点我收藏+]
    
    function getNextMonthEndDate($date){
        $firstday = date(‘Y-m-01‘, strtotime($date));
        $lastday = date(‘Y-m-d‘, strtotime("$firstday +2 month -1 day"));
        return  $lastday;
    }
    
    function next_month_today($date){        
        //获取今天是一个月中的第多少天
        $current_month_t =  date("t", strtotime($date));
        $current_month_d= date("d", strtotime($date));
        $current_month_m= date("m", strtotime($date));
        
        //获取下个月最后一天及下个月的总天数
        $next_month_end=getNextMonthEndDate($date);
        $next_month_t =  date("t", strtotime($next_month_end));
        
        $returnDate=‘‘;
        if($current_month_d==$current_month_t){//月末
            //获取下个月的月末
            $returnDate=$next_month_end;
        }else{//非月末
            //获取下个月的今天
            if($current_month_d>$next_month_t){ //如 01-30,二月没有今天,直接返回2月最后一天
                $returnDate=$next_month_end;
            }else{
                $returnDate=date("Y-m", strtotime($next_month_end))."-".$current_month_d;
            }
        }
        return $returnDate;
    }
    
    echo $date="2016-01-27";
    echo "       ";
    echo next_month_today($date);
    echo "<hr/>";

本文出自 “我的PHP之路” 博客,请务必保留此出处http://phpme.blog.51cto.com/663593/1767571

php获取下个月的今天

原文:http://phpme.blog.51cto.com/663593/1767571

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!