1) We can use the PHP basic: http://php.net/manual/en/datetime.settimezone.php
<?php
$datetime = new DateTime('2017-01-20T13:59:19+03:00', new DateTimeZone('Europe/London'));
$datetime->setTimezone(new DateTimeZone('America/New_York'));
print $datetime->format('Y-m-d H:i:s (e)');
//Output 2017-01-20 05:59:19 (America/New_York)
Or
$date = '2017-01-20T13:59:19+03:00';
$convertdate = (new \DateTime())->setTimestamp(strtotime($date));
$d = $convertdate->format(\Magento\Framework\Stdlib\DateTime::DATETIME_PHP_FORMAT);
//Output string '2017-01-20 10:59:19'
2) Magento provides some standard date time classes which we can find under vendor/magento/framework/Stdlib/DateTime
.
For example: Magento\Framework\Stdlib\DateTime\Timezone
Inject \Magento\Framework\Stdlib\DateTime\TimezoneInterface
in our constructor:
protected $timezone;
public function __construct(
\Magento\Framework\Stdlib\DateTime\TimezoneInterface $timezone,
......
)
{
$this->timezone = $timezone;
}
We can use:
$this->timezone->date($date)->format(\Magento\Framework\Stdlib\DateTime::DATETIME_PHP_FORMAT);