Home>Article>Backend Development> How to get the date a few days after the current timestamp in php

How to get the date a few days after the current timestamp in php

青灯夜游
青灯夜游 Original
2022-02-18 14:14:56 3750browse

Obtaining method: 1. Use the "date("Y-m-d",strtotime(" n day"))" statement, and the parameter "n" specifies the specific number of days; 2. Use "date("Y-m-d",time( ) (n * 24 * 3600))" statement, the parameter "n" specifies the specific number of days.

How to get the date a few days after the current timestamp in php

The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer

php gets the current time How to stamp the date of the next few days

Method 1: Use strtotime() function

"; echo "格式化当前时间戳:".date("Y-m-d H:i:s",strtotime("now"))."
"; echo "当前时间戳后1天:".date("Y-m-d H:i:s",strtotime("+1 day"))."
"; echo "当前时间戳后2天:".date("Y-m-d H:i:s",strtotime("+2 day"))."
"; echo "当前时间戳后3天:".date("Y-m-d H:i:s",strtotime("+3 day"))."
"; echo "当前时间戳后4天:".date("Y-m-d H:i:s",strtotime("+4 day"))."
"; ?>

How to get the date a few days after the current timestamp in php

date The () function is used to convert the obtained timestamp of the next few days into a readable date format.

Method 2: Use time() interval seconds

"; echo "格式化当前时间戳:".date("Y-m-d H:i:s",time())."
"; $interval = 1 * 24 * 3600; echo "当前时间戳后1天:".date("Y-m-d H:i:s",time()+$interval)."
"; $interval = 2 * 24 * 3600; echo "当前时间戳后2天:".date("Y-m-d H:i:s",time()+$interval)."
"; $interval = 3 * 24 * 3600; echo "当前时间戳后3天:".date("Y-m-d H:i:s",time()+$interval)."
"; $interval = 4 * 24 * 3600; echo "当前时间戳后4天:".date("Y-m-d H:i:s",time()+$interval)."
"; ?>

How to get the date a few days after the current timestamp in php

Recommended learning: "PHP Video Tutorial

The above is the detailed content of How to get the date a few days after the current timestamp in php. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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