PHP字符串日期加一天

strtotime() 函数将任何英文文本的日期时间描述解析为 Unix 时间戳。

strtotime(time,now)
time: 规定要解析的时间字符串。
now: 用来计算返回值的时间戳。如果省略该参数,则使用当前时间。

strtotime("now");   //当前时间的Unix时间戳
strtotime("3 October 2018");  //2018-10-03的Unix时间戳
strtotime("+5 hours") ;  //当前时间往后加5小时的Unix时间戳
strtotime('+1 day');       //当前时间往后加1天的Unix时间戳
strtotime("+1 week");   //当前时间往后加1周的Unix时间戳
strtotime("+1 week 3 days 7 hours 5 seconds");  //当前时间加1周3天7小时5秒的Unix时间戳
strtotime("next Monday");  //下周一当前时间的Unix时间戳
strtotime("last Sunday");    //上周天当前时间的Unix时间戳

因此当前时间往后加一天有如下方法:

方法一:

$date = strtotime('2019-03-19'); // 2019-03-19
$newDate = date('d-m-Y', strtotime("+1 day", $date)); // 2019-03-20

方法二:
 

$today = date('Y-m-d'); //2019-03-19
$tomorrow = strtotime($today." +".$i." day"); //2019-03-20

猜你喜欢

转载自blog.csdn.net/u012460314/article/details/88672814
今日推荐