首页 > 解决方案 > Symfony 将 1 天添加到当前日期

问题描述

我想获取实际时间并添加一天,下面的设置器是日期时间列类型,它不接受日期功能。我应该怎么办?

$password->setExpiretime(date("Y-m-d", time() + 86400));

标签: symfony

解决方案


您可以在类format的实例上使用方法DateTime

$tomorrow = new DateTime('tomorrow');
$password->setExpiretime($tomorrow->format('Y-m-d'));

更新

根据OP提交的评论,如果返回类型应该是DateTimeObject,您可以使用:

$tomorrow = new DateTime('tomorrow');
$password->setExpiretime($tomorrow);

推荐阅读