如何在教义中加2小时? [英] How to add 2 hours in doctrine?

查看:104
本文介绍了如何在教义中加2小时?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用以下代码,

protected $token;
 /** @Column(name="assigneddate", type="datetime", columnDefinition="datetime") */
private $assigneddate;


/** @Column(name="expirydate", type="datetime", columnDefinition="datetime") */
private $expirydate;

/** @PreUpdate */
public function updated()
{
    //$this->assigneddate = new \DateTime("now");
}
public function __construct()
{

    $this->expirydate = $this->expirydate = new \DateTime("now");
    $this->assigneddate = $this->assigneddate = new \DateTime("now");

}

如何添加2小时到这个?

How do I add 2 hours to this?

推荐答案

这更多是一个PHP问题。要添加时间到 DateTime PHP对象,您可以使用添加方法,该方法接受 DateInterval 对象。在您的情况下,如果要在到期日期添加2个小时:

This is more of a PHP question. To add time to a DateTime PHP object, you use the add method, which accepts a DateInterval object. In your case, if you want to add 2 hours to the expiry date:

// Create DateTime object with current time/date
$this->expirydate = new \DateTime("now");
// Add two hours
$this->expirydate->add(new \DateInterval("PT2H"));

其中PT2H表示周期时间2小时,如此处

Where "PT2H" means a "period time of 2 hours", as specified here.

这篇关于如何在教义中加2小时?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆