I have been doing this in Magento 1 to save my local date like this:
//in my custom controller
$data = $this->_filterDateTime($this->getRequest()->getPost('my_name'), array("date"));
Now, is there similar way to do this in Magento 2?
What I have done so far:
//in constructor
\Magento\Framework\Stdlib\DateTime\TimezoneInterface $timeZoneInterface,
\Magento\Framework\Stdlib\DateTime $dateTime,
$this->_timeZone = $timeZoneInterface;
$this->dateTime = $dateTime;
/////////////
//in my function
/////////////
//format d/m/y
//timezone Australia/Sydney
$date = $this->dateTime->formatDate(('17/08/18 2:16:35 pm');
//this also didn't work
$date = $this->_timeZone->convertConfigTimeToUtc('17/08/18 2:16:35 pm');
Error thrown:
date. DateTime::__construct(): Failed to parse time string (17/08/18 2:16:35 pm) at position 0 (1): Unexpected character
If I change 17/08/18 2:16:35 pm
to 12/08/18 2:16:35 pm
then it works perfectly.
I am unable to tell Magento that my format is d/m/y
.