Home > Article > Backend Development > PHP gets summary of various times (code)
The content of this article is a summary (code) of various times obtained by PHP. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.
For example: the day before the system, the previous day, the current Monday time of the previous week, etc.
echo "date('Y-m-d',time())";
echo "date("Y-m-d",strtotime("-1 day"))"; 需要前几天就减去(-) 需要几天后就加(+)
//上周周日的日期 $lastSunday = date('Y-m-d', strtotime('-1 sunday', time())); //根据时间差 减去6天前,算出上周周一日期 $lastMonday = date('Y-m-d',strtotime('$lastSunday -6 day',$ss));
$today = date('Y-m-d',time()); //获取当前周的第几天 周日是 0 周一到周六是 1 - 6 $w=date('w',strtotime($today)); $first=1; //获取本周开始日期,如果$w是0,则表示周日,减去 6 天 $weekStart=date('Y-m-d 00:00:00',strtotime("$today-".($w ? $w - $first : 6).' days')); //本周结束日期 $weekEnd=date('Y-m-d 23:59:59',strtotime("$weekStart +6 days")); //前一周的起始时间 $weekStart = date('Y-m-d 00:00:00',strtotime("$weekStart -7 days")); $weekEnd = date('Y-m-d 23:59:59',strtotime("$weekEnd -7 days")););
$t = date('t',strtotime('-1 month'));
Related recommendations:
The implementation code of ftp upload and download function in php
php implements file upload and download Method (code)
The above is the detailed content of PHP gets summary of various times (code). For more information, please follow other related articles on the PHP Chinese website!