Home>Article>Backend Development> How to get the date a few days after the current timestamp in php
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.
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"))."
"; ?>
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)."
"; ?>
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!