美文网首页
常用PHP时间总结

常用PHP时间总结

作者: 众神开挂 | 来源:发表于2020-04-29 20:40 被阅读0次

常用PHP时间总结:


<?php
//今天
$today = date("Y-m-d");
$today_begin = date('Y-m-d 00:00:00');
$today_end = date('Y-m-d 23:59:59');
//昨天
$yesterday = date("Y-m-d", strtotime(date("Y-m-d"))-86400);
//上周
$lastweek_start = date("Y-m-d H:i:s",mktime(0, 0 , 0,date("m"),date("d")-date("N")+1-7,date("Y")));
$lastweek_end = date("Y-m-d H:i:s",mktime(23,59,59,date("m"),date("d")-date("N")+7-7,date("Y")));
//本周
$thisweek_start = date("Y-m-d H:i:s",mktime(0, 0 , 0,date("m"),date("d")-date("N")+1,date("Y"))); 
$thisweek_end = date("Y-m-d H:i:s",mktime(23,59,59,date("m"),date("d")-date("N")+7,date("Y"))); 
//上月
$lastmonth_start = date("Y-m-d H:i:s",mktime(0, 0 , 0,date("m")-1,1,date("Y"))); 
$lastmonth_end = date("Y-m-d H:i:s",mktime(23,59,59,date("m") ,0,date("Y"))); 
//本月
$thismonth_start = date('Y-m-01 00:00:00');
$thismonth_end = date('Y-m-t 23:59:59'); 
//本季度未最后一月天数 
$getMonthDays = date("t",mktime(0, 0 , 0,date('n')+(date('n')-1)%3,1,date("Y")));
//本季度/
$thisquarter_start = date('Y-m-d H:i:s', mktime(0, 0, 0,date('n')-(date('n')-1)%3,1,date('Y'))); 
$thisquarter_end = date('Y-m-d H:i:s', mktime(23,59,59,date('n')+(date('n')-1)%3,$getMonthDays,date('Y')));
 
//2016-08-10这天 2个月后的日期
echo date("Y-m-d",strtotime("+2 month",strtotime("2016-08-10")));
     
//当前 3个月后的日期
echo date("Y-m-d",strtotime("+3 month",time()));

相关文章

网友评论

      本文标题:常用PHP时间总结

      本文链接:https://www.haomeiwen.com/subject/dfxowhtx.html