這篇文章主要為大家展示了“php如何獲取當(dāng)前月與上個月月初及月末時間戳”,內(nèi)容簡而易懂,條理清晰,希望能夠幫助大家解決疑惑,下面讓小編帶領(lǐng)大家一起研究并學(xué)習(xí)一下“php如何獲取當(dāng)前月與上個月月初及月末時間戳”這篇文章吧。
具體如下:
當(dāng)前月
<?php $thismonth = date('m'); $thisyear = date('Y'); $startDay = $thisyear . '-' . $thismonth . '-1'; $endDay = $thisyear . '-' . $thismonth . '-' . date('t', strtotime($startDay)); $b_time = strtotime($startDay);//當(dāng)前月的月初時間戳 $e_time = strtotime($endDay);//當(dāng)前月的月末時間戳
上一月
<?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);//上個月的月末時間戳
這里對關(guān)鍵的就是date函數(shù)中的t,它是用來獲取當(dāng)前月所含天數(shù)的,28天,29天,30天,31天。含有多少天,月底就是多少號。
以上是“php如何獲取當(dāng)前月與上個月月初及月末時間戳”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對大家有所幫助,如果還想學(xué)習(xí)更多知識,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道!
網(wǎng)站名稱:php如何獲取當(dāng)前月與上個月月初及月末時間戳-創(chuàng)新互聯(lián)
分享URL:http://www.rwnh.cn/article48/icdep.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供云服務(wù)器、商城網(wǎng)站、虛擬主機(jī)、網(wǎng)站收錄、移動網(wǎng)站建設(shè)、品牌網(wǎng)站設(shè)計
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容