我得到了输出:
Warning: strtotime() expects parameter 2 to be long, string given in C:\xampp\htdocs\MindWeather\Assimilation\foreca_hourly.php on line 17
Today is 2014117, Tomorrow is 1970101
我的代码是:
$TodayIs = date('Ynd');
$nextdate = date('Ynd', strtotime($TodayIs,'+ 1 day'));
echo "<br><br> Today is $TodayIs, Tomorrow is $nextdate<br><br>";
我真的不希望得到1970年答案。它应该显示“今天是2014117,明天是2014118”而不是“今天是2014117,明天是1970101”
答案 0 :(得分:2)
strtotime的第二个参数默认为当前时间。因此,以下内容应产生预期的结果:
$nextdate = date('Ynd', strtotime('+1 day'));
// Today is 2014117, Tomorrow is 2014118
答案 1 :(得分:0)
为什么不使用DateTime
类?
<?php
$date = new DateTime();
echo "Today is ".$date->format('Y/m/d');
$date->add(new DateInterval('P1D'));
echo "<br>Tomorrow is ".$date->format('Y/m/d');
输出:
今天是2014/01/17
明天是2014/01/18
答案 2 :(得分:0)
试试这样:
$TodayIs = date('Ynd');
$nextdate = date('Ynd', strtotime('+ 1 day'));
echo "<br><br> Today is $TodayIs, Tomorrow is $nextdate<br><br>";
PHPfiddle链接:http://phpfiddle.org/lite/code/bnf-scw
答案 3 :(得分:0)
试试这个:
$date = '2013-10-15';
$new_time = strtotime('+1 day', strtotime($date));
echo date('d-m-Y', $new_time); //displays 2013-10-16