我对形式的PHP日期2013-01-22
,我想明天的日期相同的格式,因此,例如2013-01-23
。
这怎么可能用PHP?
我对形式的PHP日期2013-01-22
,我想明天的日期相同的格式,因此,例如2013-01-23
。
这怎么可能用PHP?
使用日期时间
$datetime = new DateTime('tomorrow');
echo $datetime->format('Y-m-d H:i:s');
要么:
$datetime = new DateTime('2013-01-22');
$datetime->modify('+1 day');
echo $datetime->format('Y-m-d H:i:s');
要么:
$datetime = new DateTime('2013-01-22');
$datetime->add(new DateInterval("P1D"));
echo $datetime->format('Y-m-d H:i:s');
或在PHP 5.4+:
echo (new DateTime('2013-01-22'))->add(new DateInterval("P1D"))
->format('Y-m-d H:i:s');
$tomorrow = date("Y-m-d", strtotime('tomorrow'));
要么
$tomorrow = date("Y-m-d", strtotime("+1 day"));
帮助链接: 的strtotime()
既然你这个标记用的strtotime ,你可以用用它+1 day
修改,如下所示:
$tomorrow_timestamp = strtotime('+1 day', strtotime('2013-01-22'));
这就是说,它是一个更好的解决方案, 使用日期时间 。
<? php
//1 Day = 24*60*60 = 86400
echo date("d-m-Y", time()+86400);
?>
echo date ('Y-m-d',strtotime('+1 day', strtotime($your_date)));
使用DateTime
:
从现在得到明天:
$d = new DateTime('+1day');
$tomorrow = $d->format('d/m/Y h.i.s');
echo $tomorrow;
结果:28/06/2017 20年8月13日
从日得到明天:
$d = new DateTime('2017/06/10 08.16.35 +1day')
$tomorrow = $d->format('d/m/Y h.i.s');
echo $tomorrow;
结果:2017年11月6日35年8月16日
希望能帮助到你!
/**
* get tomorrow's date in the format requested, default to Y-m-d for MySQL (e.g. 2013-01-04)
*
* @param string
*
* @return string
*/
public static function getTomorrowsDate($format = 'Y-m-d')
{
$date = new DateTime();
$date->add(DateInterval::createFromDateString('tomorrow'));
return $date->format($format);
}
被怪它看起来它工作完全正常: date_create( '2016-02-01 + 1 day' );
echo date_create( $your_date . ' + 1 day' )->format( 'Y-m-d' );
应该这样做
这里的工作职能
function plus_one_day($date){
$date2 = formatDate4db($date);
$date1 = str_replace('-', '/', $date2);
$tomorrow = date('Y-m-d',strtotime($date1 . "+1 days"));
return $tomorrow; }
$date = '2013-01-22';
$time = strtotime($date) + 86400;
echo date('Y-m-d', $time);
其中86400是几秒钟的一天#。