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
<?php header("Content-type:text/html;charset=utf-8"); echo "当前时间戳为:".strtotime("now")."<br>"; echo "格式化当前时间戳:".date("Y-m-d H:i:s",strtotime("now"))."<br>"; echo "当前时间戳后1天:".date("Y-m-d H:i:s",strtotime("+1 day"))."<br>"; echo "当前时间戳后2天:".date("Y-m-d H:i:s",strtotime("+2 day"))."<br>"; echo "当前时间戳后3天:".date("Y-m-d H:i:s",strtotime("+3 day"))."<br>"; echo "当前时间戳后4天:".date("Y-m-d H:i:s",strtotime("+4 day"))."<br>"; ?>
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
<?php header("Content-type:text/html;charset=utf-8"); echo "当前时间戳为:".time()."<br>"; echo "格式化当前时间戳:".date("Y-m-d H:i:s",time())."<br>"; $interval = 1 * 24 * 3600; echo "当前时间戳后1天:".date("Y-m-d H:i:s",time()+$interval)."<br>"; $interval = 2 * 24 * 3600; echo "当前时间戳后2天:".date("Y-m-d H:i:s",time()+$interval)."<br>"; $interval = 3 * 24 * 3600; echo "当前时间戳后3天:".date("Y-m-d H:i:s",time()+$interval)."<br>"; $interval = 4 * 24 * 3600; echo "当前时间戳后4天:".date("Y-m-d H:i:s",time()+$interval)."<br>"; ?>
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!