亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

php日期時間計算

標簽:
PHP

//php获取今天日期

date("Y-m-d");    

//php获取昨天日期    

date("Y-m-d",strtotime("-1 day"))    

//php获取明天日期    

date("Y-m-d",strtotime("+1 day"))    

//php获取一周后日期    

date("Y-m-d",strtotime("+1 week"))    

//php获取一周零两天四小时两秒后时间    

date("Y-m-d G:H:s",strtotime("+1 week 2 days 4 hours 2 seconds"))    

//php获取下个星期四日期    

date("Y-m-d",strtotime("next Thursday"))    

//php获取上个周一日期    

date("Y-m-d",strtotime("last Monday"))    

//php获取一个月前日期    

date("Y-m-d",strtotime("last month"))    

//php获取一个月后日期    

date("Y-m-d",strtotime("+1 month"))    

//php获取十年后日期    

date("Y-m-d",strtotime("+10 year"))    

//php获取今天起止时间戳    

mktime(0,0,0,date('m'),date('d'),date('Y'));    

mktime(0,0,0,date('m'),date('d')+1,date('Y'))-1;    

//php获取昨天起止时间戳    

mktime(0,0,0,date('m'),date('d')-1,date('Y'));    

mktime(0,0,0,date('m'),date('d'),date('Y'))-1;    

//php获取上周起止时间戳    

mktime(0,0,0,date('m'),date('d')-date('w')+1-7,date('Y'));    

mktime(23,59,59,date('m'),date('d')-date('w')+7-7,date('Y'));    

//php获取本月起止时间戳    

mktime(0,0,0,date('m'),1,date('Y'));    

mktime(23,59,59,date('m'),date('t'),date('Y'));

 

计算起止日期(列出起止日期区间所有日期)

$data=$this->date_range(date('Y-m-d',$time2),date('Y-m-d',$time1));

//起止日期计算

    function date_range($first, $last, $step = '+1 day', $format = 'Y-m-d')

    {

        $dates   = array();

        $current = strtotime($first);

        $last    = strtotime($last);

 

        while ($current <= $last) {

            $dates[] = date($format, $current);

            $current = strtotime($step, $current);

        }

        return $dates;

    }

     

  /**

   * 计算上一个月的今天,如果上个月没有今天,则返回上一个月的最后一天

   * @param type $time

   * @parma key 传入加减的月份数字

   * @return type

   */

   function last_month_today($time,$key=''){

      $last_month_time = mktime(date("G", $time), date("i", $time),

          date("s", $time), date("n", $time), 0, date("Y", $time));

      $last_month_t =  date("t", $last_month_time);

 

      if ($last_month_t < date("j", $time)) {

          return date("Y-m-t H:i:s", $last_month_time);

      }

if(isset($key)&&!empty($key)){

    return date(date("Y-m",strtotime("-".$key. "month")) . "-d", $time);

}else{

    return date(date("Y-m", $last_month_time) . "-d", $time);

}

 

  }


點擊查看更多內容
TA 點贊

若覺得本文不錯,就分享一下吧!

評論

作者其他優質文章

正在加載中
  • 推薦
  • 評論
  • 收藏
  • 共同學習,寫下你的評論
感謝您的支持,我會繼續努力的~
掃碼打賞,你說多少就多少
贊賞金額會直接到老師賬戶
支付方式
打開微信掃一掃,即可進行掃碼打賞哦
今天注冊有機會得

100積分直接送

付費專欄免費學

大額優惠券免費領

立即參與 放棄機會
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號

舉報

0/150
提交
取消