《PHP應用:php獲取當前月與上個月月初及月末時間戳的方法》要點:
本文介紹了PHP應用:php獲取當前月與上個月月初及月末時間戳的方法,希望對您有用。如果有疑問,可以聯系我們。
PHP教程本文實例講述了php獲取當前月與上個月月初及月末時間戳的方法.分享給大家供大家參考,具體如下:
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教程上一月
PHP教程
<?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);//上個月的月末時間戳
PHP教程這里對關鍵的就是date函數中的t,它是用來獲取當前月所含天數的,28天,29天,30天,31天.含有多少天,月底就是多少號.
PHP教程PS:本站還提供了一個Unix時間戳轉換工具,包含了各種常見語言針對時間戳的操作方法,提供給大家參考:
PHP教程Unix時間戳(timestamp)轉換工具:
http://tools.jb51.net/code/unixtime
PHP教程更多關于PHP相關內容感興趣的讀者可查看本站專題:《php日期與時間用法總結》、《PHP數學運算技巧總結》、《PHP數組(Array)操作技巧大全》、《PHP數據結構與算法教程》、《php程序設計算法總結》、《php正則表達式用法總結》、《PHP運算與運算符用法總結》、《php字符串(string)用法總結》及《php常見數據庫操作技巧匯總》
PHP教程希望本文所述對大家PHP程序設計有所幫助.
轉載請注明本頁網址:
http://www.snjht.com/jiaocheng/2504.html