- 相關(guān)推薦
PHP獲取今天開(kāi)始和結束的時(shí)間戳
時(shí)間戳在php中可以精確到秒了,那么我們今天要給各位舉例子是關(guān)于今天的時(shí)間戳計算哦,接下來(lái)我們一起來(lái)看看這篇關(guān)于PHP獲取今天開(kāi)始和結束的時(shí)間戳例子吧。
例子:
$t = time();
//開(kāi)始時(shí)間戳
$start = mktime(0,0,0,date("m",$t),date("d",$t),date("Y",$t));
//結束時(shí)間戳
$end = mktime(23,59,59,date("m",$t),date("d",$t),date("Y",$t));
mktime 函數的定義和具體用法記錄一下
語(yǔ)法
mktime(hour,minute,second,month,day,year,is_dst)
例子 今日、昨日、上周、本月的起始時(shí)間戳和結束時(shí)間戳
//開(kāi)始時(shí)間截
$start=mktime(0,0,0,date(“m”),date(“d”),date(“Y”));
//結束時(shí)間截:
$end=mktime(0,0,0,date(‘m’),date(‘d’)+1,date(‘Y’))-1;
//php獲取昨日起始時(shí)間戳和結束時(shí)間戳
$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獲取上周起始時(shí)間戳和結束時(shí)間戳
$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獲取本月起始時(shí)間戳和結束時(shí)間戳
$beginThismonth=mktime(0,0,0,date(‘m’),1,date(‘Y’));
$endThismonth=mktime(23,59,59,date(‘m’),date(‘t’),date(‘Y’));
定義和用法:
mktime() 函數返回一個(gè)日期的 Unix 時(shí)間戳。
參數總是表示 GMT 日期,因此 is_dst 對結果沒(méi)有影響。
參數可以從右到左依次空著(zhù),空著(zhù)的參數會(huì )被設為相應的當前 GMT 值。
【PHP獲取今天開(kāi)始和結束的時(shí)間戳】相關(guān)文章:
如何獲取PHP數組的鍵與值呢03-31
《PHP編程最快明白》第八講:php啟發(fā)和小結03-31
PHP中MySQL、MySQLi和PDO的用法和區別03-10