I wanted to get the current date and time as created_at. I have tried all the ways I found on google but nothing works for me. It showing error while running my module.
use Magento\Framework\View\Result\PageFactory;
protected $_timezone;
/**
* @param \Magento\Backend\App\Action\Context $context
*/
public function __construct(
Context $context,
\Magento\Framework\Stdlib\DateTime\DateTimeFactory $timezone,
PageFactory $resultPageFactory
) {
$this->_timezone = $timezone;
$this->resultPageFactory = $resultPageFactory;
return parent::__construct($context,$resultPageFactory);
}
public function execute()
{
$date = $this->_timezone->gmtDate();
echo $date; die;
}
But when i am using i am getting this error: Magento\Framework\ObjectManager\Factory\Compiled->create('Neo\Demo\Control...', array()) called at [vendor/magento/framework/ObjectManager/ObjectManager.php:56]