標籤:
php 擷取今日、昨日、上周、本月的起始時間戳記和結束時間戳記的方法,主要使用到了 php 的時間函數 mktime。下面首先還是直奔主題以樣本說明如何使用 mktime 擷取今日、昨日、上周、本月的起始時間戳記和結束時間戳記,然後在介紹一下 mktime 函數作用和用法。
//php擷取今日開始時間戳和結束時間戳記
$beginToday=mktime(0,0,0,date(‘m‘),date(‘d‘),date(‘Y‘));
$endToday=mktime(0,0,0,date(‘m‘),date(‘d‘)+1,date(‘Y‘))-1;
//php擷取昨日起始時間戳記和結束時間戳記
$beginYesterday=mktime(0,0,0,date(‘m‘),date(‘d‘)-1,date(‘Y‘));
$endYesterday=mktime(0,0,0,date(‘m‘),date(‘d‘),date(‘Y‘))-1;
//php擷取上周起始時間戳記和結束時間戳記
$beginLastweek=mktime(0,0,0,date(‘m‘),date(‘d‘)-date(‘w‘)+1-7,date(‘Y‘));
$endLastweek=mktime(23,59,59,date(‘m‘),date(‘d‘)-date(‘w‘)+7-7,date(‘Y‘));
//php擷取本月起始時間戳記和結束時間戳記
$beginThismonth=mktime(0,0,0,date(‘m‘),1,date(‘Y‘));
$endThismonth=mktime(23,59,59,date(‘m‘),date(‘t‘),date(‘Y‘));
PHP mktime() 函數用於返回一個日期的 Unix 時間戳記。
文法
mktime(hour,minute,second,month,day,year,is_dst)
參數 描述
hour 可選。規定小時。
minute 可選。規定分鐘。
second 可選。規定秒。
month 可選。規定用數字表示的月。
day 可選。規定天。
year 可選。規定年。在某些系統上,合法值介於 1901 - 2038 之間。不過在 PHP 5 中已經不存在這個限制了。
is_dst
可選。如果時間在日光節約時間(DST)期間,則設定為1,否則設定為0,若未知,則設定為-1。
自 5.1.0 起,is_dst 參數被廢棄。因此應該使用新的時區處理特性。
用法
參數總是表示 GMT 日期,因此 is_dst 對結果沒有影響。
參數可以從右至左依次空著,空著的參數會被設為相應的當前 GMT 值。
注意在 PHP 5.1 之前,如果該函數的參數非法,則會返回 false。
另外需要注意的是該函數對於日期運算和驗證非常有用。它可以自動校正越界的輸入,如:
echo(date("M-d-Y",mktime(0,0,0,12,36,2001)));
beijing.jinti.com/licai/21878599.htm
beijing.jinti.com/licai/21878687.htm
beijing.jinti.com/licai/21878737.htm
beijing.jinti.com/licai/21878791.htm
www.talkforex.com/thread-811022-1-1.html
www.99inf.com/jinrong/pmdd/1098054.html
www.99inf.com/jinrong/qhqq/1098018.html
www.99inf.com/jinrong/qhqq/1098010.html
www.99inf.com/jinrong/yhbx/1098044.html
beijing.jinti.com/licai/21879338.htm
beijing.jinti.com/licai/21879394.htm
php 擷取今日、昨日、上周、本月的起始時間戳記和結束時間戳記的方法