Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/274.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 将天添加到时间戳_Php - Fatal编程技术网

Php 将天添加到时间戳

Php 将天添加到时间戳,php,Php,我正试图在PHP中使用以下内容向timestmp添加一定数量的天数: $capturedDate = '2008-06-20'; $endDate = strtotime($capturedDate); $endDate2 = strtotime('+1 day',$endDate); echo $endDate2; 但是它的显示:1216526400 有什么想法吗?试试: echo date("Y-m-d H:i:s",$endDate2); 或(仅限日期): 您可以在此处找到有关如

我正试图在PHP中使用以下内容向timestmp添加一定数量的天数:

$capturedDate = '2008-06-20'; 
$endDate = strtotime($capturedDate); 
$endDate2 = strtotime('+1 day',$endDate); 
echo $endDate2;
但是它的显示:
1216526400

有什么想法吗?

试试:

echo date("Y-m-d H:i:s",$endDate2);
或(仅限日期):

您可以在此处找到有关如何格式化字符串的文档:

创建Unix时间戳,因此如果希望显示格式化的日期,则需要将时间戳作为参数传递给日期函数,如下所示:

$capturedDate = '2008-06-20'; 
$endDate = strtotime($capturedDate); 
$endDate2 = strtotime('+1 day',$endDate);
echo date('Y-m-d', $endDate2);
此外,如果要显示其他信息,可以在函数中使用多种参数

e、 g.:
echo日期('Y-m-dh:i:s',$endDate2)
回显日期($Y-m-d h:i:SA',$endDate2)
等。

strotime()
将日期转换为unix时间戳,即自1970年1月1日以来的秒数。如果需要日期输出,必须首先通过
date()
运行完成的时间戳

$capturedDate = '2008-06-20'; 
$endDate = strtotime($capturedDate.' +1 day'); 
echo date("Y-m-d", $endDate);

关闭后,只需使用
date(“所需格式“,$endDate2”)将时间戳转换回日期格式即可

您应该使用DateTime来处理日期。它的时区友好

$datetime = new DateTime('2008-06-20');
$datetime->modify('+1 day');
echo $datetime->getTimestamp();

DateTime是处理日期的一种非常好的方法。您可以这样尝试:

$capturedDate = '2008-06-20'; 
$date = DateTime::createFromFormat('Y-m-d', $capturedDate)->modify('+1 day');
echo $date->getTimestamp();

你期望的输出是什么?
$capturedDate = '2008-06-20'; 
$date = DateTime::createFromFormat('Y-m-d', $capturedDate)->modify('+1 day');
echo $date->getTimestamp();