从php的date()函数中获取日期


Getting the date from PHP's date() function

如何使用PHP的date()函数来获取第二天的日期?我可以很容易地得到今天的日期。例如,如果今天是7月14日,我想得到7月15日。

date('j F', strtotime('+1 day'));
date('y-m-d', strtotime('+1 day'));

可以使用strtotime函数

strtotime("+1 day"); // will give u the next day
<?php
$timestamp = time();
$tomorrow = date("j F", $timestamp+3600*24);
?>

如果你坚持日期:

日期("…你的格式…, time() + 60 * 60 * 24);//;见编辑证明

那么你就有了明天的时间戳,你可以把它转换成一个格式化的日期。

编辑:

对于添加(60*60*24)的批评

for($i = 0; $i < 4*365; $i++)
{
   $t = time() + $i*60*60*24;
  if(strtotime("+1 day", $t) != ( $t + (60*60*24) ) )
  {
    echo "x: ".$t,PHP_EOL;
  }
}

表明,仅仅加上60*60*24是不够的:

x: 1319882214
x: 1332583014
x: 1351331814
x: 1364637414
x: 1382781414
x: 1396087014
x: 1414231014
x: 1427536614