PHP 指定时间戳 加减指定秒、分钟、小时等

php如何在某个时间上加一天?一小时? 时间加减

<?php
date_default_timezone_set('PRC'); //默认时区
echo "今天:",date("Y-m-d",time()),"<br>";
echo "今天:",date("Y-m-d",strtotime("18 june 2008")),"<br>";
echo "昨天:",date("Y-m-d",strtotime("-1 day")),"<br>";
echo "明天:",date("Y-m-d",strtotime("+1 day")),"<br>";
echo "一周后:",date("Y-m-d",strtotime("+1 week")),"<br>";
echo "一周零两天四小时两秒后:",date("Y-m-d G:H:s",strtotime("+1 week 2 days 4 hours 2 seconds")), "<br>";
echo "下个星期四:",date("Y-m-d",strtotime("next Thursday")),"<br>";
echo "上个周一:".date("Y-m-d",strtotime("last Monday"))."<br>";
echo "一个月前:".date("Y-m-d",strtotime("last month"))."<br>";
echo "一个月后:".date("Y-m-d",strtotime("+1 month"))."<br>";
echo "十年后:".date("Y-m-d",strtotime("+10 year"))."<br>";


echo "今天:",date('Y-m-d H:i:s'),"<br>";//输出当前时间
echo "明天:",date('Y-m-d H:i:s',strtotime('+1 day'));//输出明天时间
//这里+1 day 可以修改参数1为任何想需要的数  day也可以改成year(年),month(月),hour(小时),minute(分),second(秒)//如:
date('Y-m-d H:i:s',strtotime("+1 day +1 hour +1 minute");
?>

 

<?php
// 当前时间戳  格式:2019-03-13 18:00:00
echo date('Y-m-d H:i:s', strtotime('now'));
 
// 当前时间戳+1秒
echo date('Y-m-d H:i:s', strtotime('+1second'));
 
// 当前时间戳+1分
echo date('Y-m-d H:i:s', strtotime('+1minute'));
 
// 当前时间戳+1小时
echo date('Y-m-d H:i:s', strtotime('+1hour'));
 
// 当前时间戳+1天 
echo date('Y-m-d H:i:s', strtotime('+1day'));
 
// 当前时间戳+1周 
echo date('Y-m-d H:i:s', strtotime('+1week'));
 
// 当前时间戳+1月 
echo date('Y-m-d H:i:s', strtotime('+1month'));
 
// 当前时间戳+1年
echo date('Y-m-d H:i:s', strtotime('+1year'));
 
// 当前时间戳+12年,12月,12天,12小时,12分,12秒
echo date('Y-m-d H:i:s', strtotime('+12year 12month 12day 12hour 12minute 12second'));
 
$t = 1483967416; // 指定时间戳
 
echo $date = date('Y-m-d H:i:s', $t);
 
/*方法一*/
 
// 指定时间戳+1天
echo date('Y-m-d H:i:s', $t+1*24*60*60);
 
// 指定时间戳+1年
echo date('Y-m-d H:i:s', $t+365*24*60*60);
 
/*方法二*/
 
// 指定时间戳+1天
echo date('Y-m-d H:i:s', strtotime("+1day", $t));
 
// 指定时间戳+1年
echo date('Y-m-d H:i:s', strtotime("+1year", $t));

 

<?php
// 获取上个月第一天及最后一天
echo date('Y-m-01', strtotime('-1 month'));
echo date('Y-m-t', strtotime('-1 month'));
 
// 获取当月第一天及最后一天
echo $beginDate = date('Y-m-01', strtotime(date("Y-m-d")));
echo date('Y-m-d', strtotime("$beginDate +1 month -1 day"));
计算机