php怎么给指定日期增加天数

本教程操作环境:windows7系统、php7.1版、DELL G3电脑

php给指定日期增加天数

实现思想:

  • 将指定日期转为时间戳;

  • 将需要添加的天数转为秒数值;

  • 时间戳和秒数相加形成新的时间戳;

  • 将新时间戳转为日期格式。

实现代码:

<?php
header("Content-type:text/html;charset=utf-8");
$start = strtotime('2022-2-13');;
$interval = 2 * 24 * 3600;//2天
echo date('Y-m-d',$start + $interval);
?>

说明:

strtotime() 函数将任何英文文本的日期或时间描述解析为 Unix 时间戳(自 January 1 1970 00:00:00 GMT 起的秒数)。

date() 函数格式化本地日期和时间,并返回已格式化的日期字符串。

© 版权声明
THE END
喜欢就支持一下吧
点赞0 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容