How to get the date several months later in php

青灯夜游
Release: 2023-03-15 13:18:01
Original
2911 people have browsed it

php获取几月后日期的方法:1、使用“strtotime("+N month")”语句获取几月后的时间戳,参数“N”指定具体月数;2、使用“date("Y-m-d",时间戳)”语句格式化获取的时间戳,将其转为“年-月-日”的日期格式。

How to get the date several months later in php

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

php怎么获取几月后的日期

实现步骤:

  • 使用strtotime() 函数进行日期的加减运算,获取几月后的时间戳。

  • 使用date() 函数格式获取的时间戳,将其转为指定的时间日期格式。

实现代码:

"; echo "格式化当前时间戳:".date("Y-m-d H:i:s",strtotime("now"))."

"; echo "1个月后的时间戳:".strtotime("+1 month")."
"; echo "格式化时间戳:".date("Y-m-d H:i:s",strtotime("+1 month"))."

"; echo "当前时间戳后2个月:".date("Y-m-d H:i:s",strtotime("+2 month"))."
"; echo "当前时间戳后3天:".date("Y-m-d H:i:s",strtotime("+3 month"))."
"; echo "当前时间戳后4天:".date("Y-m-d H:i:s",strtotime("+4 month"))."
"; ?>
Copy after login

How to get the date several months later in php

说明:

PHP strtotime() 函数有两种用法:一种是将字符串形式的、用英文文本描述的日期时间解析为 UNIX 时间戳,一种是用来计算一些日期时间的间隔。

strtotime() 函数的使用示例如下:

"; echo strtotime("10 September 2000"), "
"; echo strtotime("+1 day"), "
"; echo strtotime("+1 week"), "
"; echo strtotime("+1 week 2 days 4 hours 2 seconds"), "
"; echo strtotime("next Thursday"), "
"; echo strtotime("last Monday"), "
"; ?>
Copy after login

How to get the date several months later in php

Copy after login

How to get the date several months later in php

推荐学习:《PHP视频教程

The above is the detailed content of How to get the date several months later in php. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!