Magento 2: How to get current date, date time with format in .phtml file?
protected $_date;
public function __construct(\Magento\Framework\Stdlib\DateTime\TimezoneInterface $date)
{
$this->_date = $date;
}
then use like this
$this->_date->date()->format('Y-m-d H:i:s');
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.