?php
date_default_timezone_set('Asia/Shanghai');
echo "今天:".date("Y-m-d H:i:s")."br>";
echo "昨天:".date("Y-m-d",strtotime("-1 day")), "br>";
echo "明天:".date("Y-m-d",strtotime("+1 day")). "br>";
echo "一周后:".date("Y-m-d",strtotime("+1 week")). "br>";
echo "一周前:".date("Y-m-d",strtotime("-1 week")). "br>";
echo "一周零兩天四小時(shí)兩秒后:".date("Y-m-d G:H:s",strtotime("+1 week 2 days 4 hours 2 seconds")). "br>";
echo "下個(gè)星期四:".date("Y-m-d",strtotime("next Thursday")). "br>";
echo "上個(gè)周一:".date("Y-m-d",strtotime("last Monday"))."br>";
echo "一個(gè)月前:".date("Y-m-d",strtotime("last month"))."br>";
echo "一個(gè)月后:".date("Y-m-d",strtotime("+1 month"))."br>";
echo "十年后:".date("Y-m-d",strtotime("+10 year"))."br>";
echo 'hr/>';
//php獲取今日開始時(shí)間戳和結(jié)束時(shí)間戳
$beginToday=mktime(0,0,0,date('m'),date('d'),date('Y'));
$endToday=mktime(0,0,0,date('m'),date('d')+1,date('Y'))-1;
echo "今日開始時(shí)間戳和結(jié)束時(shí)間戳",'開始:',$beginToday,'結(jié)束:',$endToday,'br/>';
echo "今日開始時(shí)間:",date("Y-m-d H:i:s",$beginToday),'br/>';
echo "今日結(jié)束時(shí)間:",date("Y-m-d H:i:s",$endToday),'br/>';
echo 'hr/>';
//php獲取昨日起始時(shí)間戳和結(jié)束時(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;
echo "昨日開始時(shí)間戳和結(jié)束時(shí)間戳",'開始:',$beginYesterday,'結(jié)束:',$endYesterday,'br/>';
echo "昨日開始時(shí)間:",date("Y-m-d H:i:s",$beginYesterday),'br/>';
echo "昨日結(jié)束時(shí)間:",date("Y-m-d H:i:s",$endYesterday),'br/>';
echo 'hr/>';
//php獲取上周起始時(shí)間戳和結(jié)束時(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'));
echo "上周開始時(shí)間戳和結(jié)束時(shí)間戳",'開始:',$beginLastweek,'結(jié)束:',$endLastweek,'br/>';
echo "上周開始時(shí)間:",date("Y-m-d H:i:s",$beginLastweek),'br/>';
echo "上周結(jié)束時(shí)間:",date("Y-m-d H:i:s",$endLastweek),'br/>';
echo 'hr/>';
//php獲取本月起始時(shí)間戳和結(jié)束時(shí)間戳
$beginThismonth=mktime(0,0,0,date('m'),1,date('Y'));
$endThismonth=mktime(23,59,59,date('m'),date('t'),date('Y'));
echo "本月開始時(shí)間戳和結(jié)束時(shí)間戳",'開始:',$beginThismonth,'結(jié)束:',$endThismonth,'br/>';
echo "本月開始時(shí)間:",date("Y-m-d H:i:s",$beginThismonth),'br/>';
echo "本月結(jié)束時(shí)間:",date("Y-m-d H:i:s",$endThismonth),'br/>';
?>
今天:2019-07-06 10:23:11
昨天:2019-07-05
明天:2019-07-07
一周后:2019-07-13
一周前:2019-06-29
一周零兩天四小時(shí)兩秒后:2019-07-15 14:14:13
下個(gè)星期四:2019-07-11
上個(gè)周一:2019-07-01
一個(gè)月前:2019-06-06
一個(gè)月后:2019-08-06
十年后:2029-07-06
--------------------------------------------------------------------------------
今日開始時(shí)間戳和結(jié)束時(shí)間戳開始:1562342400結(jié)束:1562428799
今日開始時(shí)間:2019-07-06 00:00:00
今日結(jié)束時(shí)間:2019-07-06 23:59:59
--------------------------------------------------------------------------------
昨日開始時(shí)間戳和結(jié)束時(shí)間戳開始:1562256000結(jié)束:1562342399
昨日開始時(shí)間:2019-07-05 00:00:00
昨日結(jié)束時(shí)間:2019-07-05 23:59:59
--------------------------------------------------------------------------------
上周開始時(shí)間戳和結(jié)束時(shí)間戳開始:1561305600結(jié)束:1561910399
上周開始時(shí)間:2019-06-24 00:00:00
上周結(jié)束時(shí)間:2019-06-30 23:59:59
--------------------------------------------------------------------------------
本月開始時(shí)間戳和結(jié)束時(shí)間戳開始:1561910400結(jié)束:1564588799
本月開始時(shí)間:2019-07-01 00:00:00
本月結(jié)束時(shí)間:2019-07-31 23:59:59
PS:這里再為大家推薦幾款時(shí)間及日期相關(guān)工具供大家參考:
更多關(guān)于PHP相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《php日期與時(shí)間用法總結(jié)》、《PHP數(shù)組(Array)操作技巧大全》、《PHP基本語法入門教程》、《PHP運(yùn)算與運(yùn)算符用法總結(jié)》、《php面向?qū)ο蟪绦蛟O(shè)計(jì)入門教程》、《php字符串(string)用法總結(jié)》、《php+mysql數(shù)據(jù)庫操作入門教程》及《php常見數(shù)據(jù)庫操作技巧匯總》