Magento 2 Get Current Date Time
Magento 2 Get Current Date Time– Sometimes we need to get the current date time in Magento 2. It is totally different to get current date time in magento 2 than magento 1. Here in this tutorial, we are going to explain how you can get current Date Time.
Magento 2 Get Current Date Time |Current Store Date Time Example
To use datetime function in magento you need to inject DateTime as \Magento\Framework\Stdlib\DateTime\DateTime, After injecting this you will be able to access the Current Date time functions –
Magento 2 Get Current Date Time Example:
protected $date; public function __construct( \Magento\Framework\Stdlib\DateTime\DateTime $date ) { $this->date = $date; } public function myFunction(){ $date = $this->date->gmtDate(); } |
Thus you can the current date time anywhere using the above method for the current store.
Advertisements