php獲取今日、昨日、最近7天、最近30天等時間的方法


date('Y-m-d',timestamp); //輸出年-月-日
date('Y-m-d H:i:s',timestamp); //輸出年-月-日 時:分:秒

//php獲取今天日期
date("Y-m-d",strtotime("today")); //strtotime(‘today’)輸出今天的開始時間戳

date("Y-m-d",time()); //time()輸出當前秒時間戳

//php獲取昨天日期
date("Y-m-d",strtotime("-1 day")); 或 date("Y-m-d",strtotime("yesterday"));

//php獲取明天日期
date("Y-m-d",strtotime("+1 day")); 或 date("Y-m-d",strtotime("tomorrow "));

//php獲取7天后日期
date("Y-m-d",strtotime("+7 day"));

//php獲取30天后日期
date("Y-m-d",strtotime("+30 day"));

//php獲取一周后日期
date("Y-m-d",strtotime("+1 week"));

//php獲取一個月后日期
date("Y-m-d",strtotime("+1 month"));

//php獲取一個月前日期
date("Y-m-d",strtotime("last month")); 或 date("Y-m-d",strtotime("-1 month"));

//php獲取一年后日期
date("Y-m-d",strtotime("+1 year"));

//php獲取一周零兩天四小時五分鍾兩秒后時間
date("Y-m-d H:i:s",strtotime("+1 week 2 days 4 hours 5 minute 2 seconds"));

//php獲取下個星期四日期
date("Y-m-d",strtotime("next Thursday"));

//php獲取上個周一日期
date("Y-m-d",strtotime("last Monday"));

//php獲取今天起止時間戳
mktime(0,0,0,date('m'),date('d'),date('Y'));
mktime(0,0,0,date('m'),date('d')+1,date('Y'))-1;

//php獲取昨天起止時間戳
mktime(0,0,0,date('m'),date('d')-1,date('Y'));
mktime(0,0,0,date('m'),date('d'),date('Y'))-1;

//php獲取上周起止時間戳
mktime(0,0,0,date('m'),date('d')-date('w')+1-7,date('Y'));
mktime(23,59,59,date('m'),date('d')-date('w')+7-7,date('Y'));

//php獲取本月起止時間戳
mktime(0,0,0,date('m'),1,date('Y'));
mktime(23,59,59,date('m'),date('t'),date('Y'));

 

 

原作者:php獲取今日、昨日、最近7天、最近30天等的時間戳方法 | 愛國足de博客 (caizhichao.cn)


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM