/** * 计算下个月的今日 * @ $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
原文:http://www.cnblogs.com/scrit/p/3669545.html