How to get current store DateTime in Magento 2
To get current store DateTime in Magento 2, inject an instance of \Magento\Framework\Stdlib\DateTime\DateTime in your class constructor.
Also, use the following code:
1 |
protected $date; public function __construct( .... \Magento\Framework\Stdlib\DateTime\DateTime $date, .... ) { .... $this->date = $date; .... } |
Then, you will get the ability to use the following snippet in your class:
1 |
$date = $this->date->gmtDate(); |
Source (