Magento 2 Current Store Date Time

Today we talk about how in Magento 2 Current Store Date Time. Following this example you can get store date and time in block, helper, controller or model too. So let start with our example.
You need to inject in your class constructor an instance of Magento\Framework\Stdlib\DateTime\DateTime.

protected $date;
public function __construct(
   
    \Magento\Framework\Stdlib\DateTime\DateTime $date,

) {
   
    $this->date = $date;

}

Then, you can use in your class this:

$date = $this->date->gmtDate();

Qaisar Satti

Hi, I'm Qaisar Satti! I've been a developer for over 20 years, and now I love sharing what I've learned through tutorials and guides. Whether you're working with Magento, PrestaShop, or WooCommerce, my goal is to make your development journey a bit easier and more fun. When I'm not coding or writing, you can find me exploring new tech trends and hanging out with the amazing developer community. Thanks for stopping by, and happy coding!

Leave a Reply