這篇文章主要為大家展示了“php如何獲取當前月與上個月月初及月末時間戳”,內容簡而易懂,條理清晰,希望能夠幫助大家解決疑惑,下面讓小編帶領大家一起研究并學習一下“php如何獲取當前月與上個月月初及月末時間戳”這篇文章吧。
具體如下:
當前月
<?php $thismonth = date('m'); $thisyear = date('Y'); $startDay = $thisyear . '-' . $thismonth . '-1'; $endDay = $thisyear . '-' . $thismonth . '-' . date('t', strtotime($startDay)); $b_time = strtotime($startDay);//當前月的月初時間戳 $e_time = strtotime($endDay);//當前月的月末時間戳
上一月
<?php $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);//上個月的月末時間戳
這里對關鍵的就是date函數中的t,它是用來獲取當前月所含天數的,28天,29天,30天,31天。含有多少天,月底就是多少號。
以上是“php如何獲取當前月與上個月月初及月末時間戳”這篇文章的所有內容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內容對大家有所幫助,如果還想學習更多知識,歡迎關注億速云行業資訊頻道!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。