PHP获取本月起始和终止时间戳
生活随笔
收集整理的這篇文章主要介紹了
PHP获取本月起始和终止时间戳
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
一、本月起始和結束
//獲取本月開始的時間戳 $beginThismonth=mktime(0,0,0,date('m'),1,date('Y')); //獲取本月結束的時間戳 $endThismonth=mktime(23,59,59,date('m'),date('t'),date('Y')); View Code二、上月起始和結束
? ? ?寫法一:
$m = date('Y-m-d', mktime(0,0,0,date('m')-1,1,date('Y'))); //上個月的開始日期$t = date('t',strtotime($m)); //上個月共多少天$start = date('Y-m-d', mktime(0,0,0,date('m')-1,1,date('Y'))); //上個月的開始日期$end = date('Y-m-d', mktime(0,0,0,date('m')-1,$t,date('Y'))); //上個月的結束日期//echo 15*24*3600;//echo 30*24*3600;$time=strtotime($start);dump(date('Y-m-d H:i:s',$time));//2017-06-01 00:00:00$jieshu=strtotime($end);dump(date('Y-m-d H:i:s',$jieshu));//2017-06-30 00:00:00?
? ? ?寫法二:
?
$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));$b_time = strtotime($lastStartDay);//上個月的月初時間戳$e_time = strtotime($lastEndDay);//上個月的月末時間戳2017-06-30 00:00:00(注意 是最后一天的開始時間點)?
轉載于:https://www.cnblogs.com/meetuj/p/7112493.html
總結
以上是生活随笔為你收集整理的PHP获取本月起始和终止时间戳的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: DOM编程练习(慕课网题目)
- 下一篇: 动态规划算法php,php算法学习之动态