Create new Datetime and set Timezone in magento 2

by The Lord Of The Shells   Last Updated April 03, 2017 11:09 AM

Does magento 2 support create new Datetime and set Timezone for it? I'm trying to create a new Datetime and set Timezone for it in magento 2 by following code but it's not a good way to do it because the validate code tool throws some warning. So is there any another way to do that in magento 2?. Thank for your help.

$fromDate = new \DateTime($dateFomat, new \DateTimeZone('UTC'));
$fromDate = $fromDate->setTimezone(new \DateTimeZone(date_default_timezone_get()))->format('Y-m-d H:i:s');


Related Questions


How to save local date in custom datetime field

Updated August 03, 2018 07:09 AM

Magento 2 backend form date time form field

Updated June 11, 2016 08:03 AM


Admin Grid:To save GMT time in DB

Updated December 06, 2017 07:09 AM

Datetime Error on Newsletter Template

Updated May 22, 2018 10:09 AM