Magento 2 – Get Current Date and Time in .phtml File

datedatetimemagento2phtml

I already referred Magento 2 Get Current Store Date Time

But how to use directly in .phtml file? Can able to get Date, DateTime & Also able to set it's format?

Best Answer

You can use this in phtml file :

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$objDate = $objectManager->create('Magento\Framework\Stdlib\DateTime\DateTime');
$date = $objDate->gmtDate();

But using directly object manager in phtml file is not a good practice.

Related Topic