php获取几天后时间的方法:首先创建一个PHP示例文件;然后通过“date("Y-m-d H:i:s",strtotime("3 day"));”获取3天后的时间即可。

本文操作环境:windows7系统、PHP7.1版,DELL G3电脑
php 获取N天之后时间日期的方法
例1:php获取3天之后的时间日期
代码:
立即学习“PHP免费学习笔记(深入)”;
<?php
//当前时间
echo date('Y-m-d H:i:s');
//3天之后的时期
echo date("Y-m-d H:i:s",strtotime("3 day"));
?>输出结果:
2019-11-07 23:23:25 2019-11-10 23:23:25
例2:php获取n天之后的时间日期的函数
函数代码:
<?php
function get_later($d){
return date("Y-m-d H:i:s",strtotime($d." day"));
}
?>函数调用:
<?php echo get_later(7); ?>
补充说明:
灵活的运用 php 的 strtotime(),还可以获取当前时间的前N小时,后N小间,一周之前,一月之后等的时间日期。
例:
<?php
//一小时之前的时间
echo strtotime("-1 hours");
//五小时之后的时间
echo strtotime("+5 hours");
//一周之后的时间
echo strtotime("+1 week");
//下周一的时间
echo strtotime("next Monday");
?>推荐学习:《PHP视频教程》
以上就是php怎么获取几天后时间的详细内容,更多请关注php中文网其它相关文章!
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号