<?php
date_default_timezone_set('PRC');
/**
* 获取给定月份的上一月最后一天
* @param $date string 给定日期
* @return string 上一月最后一天
*/
function get_last_month_last_day($date = ''){
if ($date != '') {
$time = strtotime($date);
} else {
$time = time();
}
$day = date('j',$time);//获取该日期是当前月的第几天
return date('Y-m-d',strtotime("-{$day} days",$time));
}
// 测试
echo get_last_month_last_day();
echo "<br />";
echo get_last_month_last_day("2013-3-21");
?>
php编写函数取得上一月的最后一天
微信公众号

手机浏览(小程序)
