1、获取前一天的开始时间和结束时间
$startTime=date("Y-m-d",strtotime("-1 day"))." 00:00:00";
$endTime=date("Y-m-d",strtotime("-1 day"))." 23:59:59";
2、获取本月剩余天数
public function lessDay()
{
$month_big = array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');
//现在的月份
$date_month_old = (int)date('m',time());
//下个月的月份
$date_month_new = $date_month_old + 1;
//下个月1号的时间戳
$date_time_new = strtotime('1 '.$month_big[$date_month_new-1].' '.date('Y',time()));
//今天的时间戳
$date_time_old = strtotime(date('d',time()).' '.$month_big[$date_month_old-1].' '.date('Y',time()));
//距下月剩余时间
$time_new = ($date_time_new - $date_time_old)/24/60/60-1;
return $time_new;
}
3、获取下个月的当前时间
public function nextMonth($date=NULL)
{
if ($date) {
$timestamp = strtotime($date);
} else {
$timestamp = time();
}
$arr = getdate($timestamp);
$time = date('H:i:s', $timestamp);
$day = $arr['mday'];
$year = $arr['year'];
if ($arr['mon'] == 12) {
$year = $arr['year'] + 1;
$month = $arr['mon'] - 11;
if($month<10){
$month = '0'.$month;
}
$firstDay = $year . '-' . $month . '-' . date('d', $timestamp) . ' ' . $time;
} else {
$month = $arr['mon']+1;
$month_maxday = date('Y-m-d', strtotime(date('Y-m-01', strtotime($year . '-' . $month . '-01')) . ' +1 month -1 day')); //某月的最后一天
$month_maxday = date("d ",strtotime($month_maxday));
if($arr['mday']>$month_maxday){
$day = $month_maxday;
}
$firstDay = date("Y-m-d", mktime(0, 0, 0, $month, $day, $year)). ' ' . $time;
}
return $firstDay;
}
nextMonth(2020-09-24); //返回 2020-10-24 00:00:00