php 获取当前时间的 前一小时、一天、一个月、一年

//获取本月起始日期
$begindate=date('Y-m-01', strtotime(date("Y-m-d")));
$enddate =date('Y-m-d', strtotime("$begindate +1 month -1 day"));


//获取一年前的日期
$begindate= date('Y-m-d', strtotime(date('Y-m-01') . ' -1 year')); 
$begindate= date("Y-m-d H:i:s", strtotime("-1 year"));


//获取一个月前的日期:其中值:-1为变量
$mothtime= date("Y-m-d H:i:s", strtotime("-1 month"));


//获取几个月以前的起始日期:其中值:-1为变量
 $begindate= date('Y-m-d', strtotime(date('Y-m-01') . ' -1 month')); // 计算出本月第一天再减一个月
 $enddate = date('Y-m-d', strtotime(date('Y-m-01') . ' -1 day')); // 计算出本月第一天再减一天


//获取一天前日期:其中值:-1为变量;-1为一天前,以此类推
$daytime= date("Y-m-d H:i:s", strtotime("-1 day"));


//获取一小时前的日期时间
$hourtime = date("Y-m-d H:i:s", strtotime("-1 hour"));

猜你喜欢

转载自blog.csdn.net/u014724048/article/details/82115233