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

PHP set db value according to server datetime

Updated September 24, 2018 19:09 PM

Magento 2 backend form date time form field

Updated June 11, 2016 08:03 AM