最新消息: 新版网站上线了!!!

php 获取上个月、下个月、本月的日期

<?php
 
  date_default_timezone_set("UTC");
 function GetTheMonth($date){//获取指定日期所在月的第一天和最后一天
  $firstday = date("Y-m-01",strtotime($date));
  $lastday = date("Y-m-d",strtotime("$firstday +1 month -1 day"));
  return array($firstday,$lastday);
 }
 function GetPurMonth($date){//获取指定日期上个月的第一天和最后一天
  $time=strtotime($date);
  $firstday=date('Y-m-01',strtotime(date('Y',$time).'-'.(date('m',$time)-1).'-01'));
  $lastday=date('Y-m-d',strtotime("$firstday +1 month -1 day"));
  return array($firstday,$lastday);
 }
 function GetNextMonth($date){//获取指定日期下个月的第一天和最后一天
  
  $arr = getdate();
  if($arr['mon'] == 12){
   $year = $arr['year'] +1;
   $month = $arr['mon'] -11;
   $day = $arr['mday'];
   if($day < 10){
    $mday = '0'.$day;
   }else {
    $mday = $day;
   }
   $firstday = $year.'-0'.$month.'-01';
   $lastday = $year.'-0'.$month.'-'.$mday;
  }else{
   $time=strtotime($date);
   $firstday=date('Y-m-01',strtotime(date('Y',$time).'-'.(date('m',$time)+1).'-01'));
   $lastday=date('Y-m-d',strtotime("$firstday +1 month -1 day"));
  }
   return array($firstday,$lastday);
 }
>

转载请注明:谷谷点程序 » php 获取上个月、下个月、本月的日期