美文网首页
获取下月月初月末时间以及获取上月月初月末时间戳

获取下月月初月末时间以及获取上月月初月末时间戳

作者: 苏大发 | 来源:发表于2017-11-21 11:58 被阅读0次
function getNextMonthDays($date){
   $timestamp=strtotime($date);
   $arr=getdate($timestamp);
   // var_dump($arr);
   if($arr['mon'] == 12){
     $year=$arr['year'] +1;
     $month=$arr['mon'] -11;
     $firstday=$year.'-0'.$month.'-01';
     $lastday=date('Y-m-d',strtotime("$firstday +1 month -1 day"));
   }else{
     $firstday=date('Y-m-01',strtotime(date('Y',$timestamp).'-'.(date('m',$timestamp)+1).'-01'));
     $lastday=date('Y-m-d',strtotime("$firstday +1 month -1 day"));
   }
   return array($firstday,$lastday);
 }
 var_dump(getNextMonthDays('2017-11-15 12:12:12'));
image.png
//获取上月月初月末时间戳
function last_month_start_end(){
    $arr = [];
    $thismonth = date('m');
    $thisyear  = date('Y');
    if ($thismonth == 1) {
        $lastmonth = 12;
        $lastyear  = $thisyear - 1;
    } else {
        $lastmonth = $thismonth - 1;
        $lastyear  = $thisyear;
    }
    $lastStartDay = $lastyear . '-' . $lastmonth . '-1';
    $lastEndDay   = $lastyear . '-' . $lastmonth . '-' . date('t', strtotime($lastStartDay)).' 23:59:59';
    $arr['last_month_start'] = strtotime($lastStartDay);
    $arr['last_month_end'] = strtotime($lastEndDay);
    return $arr;
}

相关文章

网友评论

      本文标题:获取下月月初月末时间以及获取上月月初月末时间戳

      本文链接:https://www.haomeiwen.com/subject/hznivxtx.html