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

青灯夜游
Release: 2023-03-15 11:56:01
Original
3807 people have browsed it

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

<?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>";
?>
Copy after login

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

<?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>";
?>
Copy after login

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!

Related labels:
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template