首页 > 其他 > 详细

计算上个月的今天是哪一年哪一月那一天

时间:2014-04-17 23:58:09      阅读:633      评论:0      收藏:0      [点我收藏+]
bubuko.com,布布扣
        /**
         *  计算下个月的今日
         *  @ $time 当前的时间戳
         *  @ $flag 计算上下个月的标记(+ 表示下个月 - 表示上个月)
         * **/
        function next_month_today($time , $flag="+"){ 
                //本月的时间戳
                $last_month = date("Y-m-d",$time);
                $last_month_data = explode("-", $last_month);
                switch ($flag){
                    case ‘+‘:
                                $next_month_time = mktime(date("G", $time), date("i", $time),date("s", $time), $last_month_data[‘1‘]+2, 0, date("Y", $time));
                                $last_month_t =  date("t", $next_month_time);
                                if ($last_month_t < date("j", $time))   //如果下个月的天数小于当前的日期值(例如28号小于30号)则返回下个月的月末
                                {
                                    return date("Y-m-t", $next_month_time);
                                }
                                return date(date("Y-m", $next_month_time) . "-d", $time);
                    case "-":
                                $next_month_time = mktime(date("G", $time), date("i", $time),date("s", $time), $last_month_data[‘1‘], 0, date("Y", $time));
                                $last_month_t =  date("t", $next_month_time);
                                if ($last_month_t < date("j", $time))   //如果下个月的天数小于当前的日期值(例如28号小于30号)则返回下个月的月末
                                {
                                    return date("Y-m-t", $next_month_time);
                                }
                                return date(date("Y-m", $next_month_time) . "-d", $time);
                   }
          }
bubuko.com,布布扣

 

计算上个月的今天是哪一年哪一月那一天,布布扣,bubuko.com

计算上个月的今天是哪一年哪一月那一天

原文:http://www.cnblogs.com/scrit/p/3669545.html

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