symfony - Symfony 将 1 天添加到当前日期
问题描述
我想获取实际时间并添加一天,下面的设置器是日期时间列类型,它不接受日期功能。我应该怎么办?
$password->setExpiretime(date("Y-m-d", time() + 86400));
解决方案
您可以在类format
的实例上使用方法DateTime
:
$tomorrow = new DateTime('tomorrow');
$password->setExpiretime($tomorrow->format('Y-m-d'));
更新
根据OP提交的评论,如果返回类型应该是DateTime
Object,您可以使用:
$tomorrow = new DateTime('tomorrow');
$password->setExpiretime($tomorrow);
推荐阅读
- javascript - 我该怎么做:检查单选按钮时需要更改输入?
- excel - 它是 Excel 中从特定参考中提取日期差异的函数吗?
- javascript - 如何在反应中对齐中心的按钮、文本字段和文本?
- google-cloud-armor - 谷歌云盔甲
- r - 在具有最高值的列上左连接
- powershell - 通过 Power Shell 自动创建目录
- vim - 我的 Neovim LSP 错误消息没有红色
- asp.net - 访问被拒绝异常 | 部署 ASP.NET Core 托管的 Blazor Webassembly 应用程序
- c++ - 使用linux socket时select函数中socket文件描述符加1的意义
- asp.net-core - ASP.NET Core Razor Pages 中的 return Page() 在 RedirectToPage 调用后不呈现页面