PHP acquisition time and display

1. Obtain the current system time

echo "date('Y-m-d',time())";

2. Get the day before the system
echo "date("Y-m-d",strtotime("-1 day"))";
A few days before you need to subtract (-) a few days after the plus (+)
 3. Access for the current week Monday and Sunday date on your system time
//上周周日的日期
$lastSunday = date('Y-m-d', strtotime('-1 sunday', time()));

//根据时间差 减去6天前,算出上周周一日期
$lastMonday = date('Y-m-d',strtotime('$lastSunday -6 day',$ss));
4. Get the current day of the week is Sunday 0 Monday to Saturday is 1--6

 

$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")););

 

5. The total number of days a month on
$t = date('t',strtotime('-1 month'));

6. php acquisition date three months ago

 

<?php header("content-Type: text/html; charset=utf-8");?>
<?php
$s_sdate=date("Y-m-d"); //当前时间
$moth_day=90; //月份 (转为天数)
$s_edate=date("Y-m-d",(strtotime($s_sdate)-$moth_day*84600));
echo $moth_day."前的日期为".$s_edate;
?>

 

7. 30 days after calculation date

$t = time(); // 当前时间戳
$t = strtotime("+30 days", $t); // 30天后的时间戳
echo date("Y-m-d", $t); // 格式化日期

8. The conversion date stamp 2 is then subtracted ...

$t1 = strtotime("2009-08-19");
$t2 = strtotime("2009-08-20");
$t = $t2 - $t1; // 相差天数的秒
echo (int)($t / 86400)

9. determines whether this week

 

$date = "2008-12-08";
if (isCurrentWeeks($date)) {
  echo $date."是本星期";
} else {
  echo $date."不是本星期";
}
function isCurrentWeeks($d) {
  return (date("W",strtotime($d))==date("W",strtotime("now")));
}

 


<?php
//今天
$today = date("Y-m-d");
//昨天
$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("w")+1-7,date("Y")));
$lastweek_end = date("Y-m-d H:i:s",mktime(23,59,59,date("m"),date("d")-date("w")+7-7,date("Y")));
//本周
$thisweek_start = date("Y-m-d H:i:s",mktime(0, 0 , 0,date("m"),date("d")-date("w")+1,date("Y"))); 
$thisweek_end = date("Y-m-d H:i:s",mktime(23,59,59,date("m"),date("d")-date("w")+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-d H:i:s",mktime(0, 0 , 0,date("m"),1,date("Y"))); 
$thismonth_end = date("Y-m-d H:i:s",mktime(23,59,59,date("m"),date("t"),date("Y"))); 
//本季度未最后一月天数 
$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()));

 

Guess you like

Origin blog.csdn.net/LQZ8888/article/details/90727385