0

I would like to find out the magento2 equivalent of the below code from magento 1

Mage::app()->getLocale()->storeTimeStamp()

Can anyone assist me?

0

Something like \Magento\Framework\Stdlib\DateTime\TimezoneInterface?

For example:

protected $_timezone;

public function __construct(
    \Magento\Framework\Stdlib\DateTime\TimezoneInterface $timezone,
) {
    $this->_timezone = $timezone;
}

Then you can use:

$date = $this->timezone->formatDate();

Alternatively, \Magento\Framework\Stdlib\DateTime\DateTime::gmtDate(); might give you what you want.

0
<?php
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$dateTime = $objectManager->get("Magento\Framework\Stdlib\DateTime\DateTime");
var_dump($dateTime->gmtDate());
var_dump($dateTime->gmtTimestamp());
?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.