Did anyone else had this strange problem? Error message:
Fatal error: Uncaught exception 'Exception' with message 'DateTime::__construct(): Failed to parse time string (01/18/2016 00:00 AM America/New_York) at position 17 (A): The timezone could not be found in the database'
Exception: DateTime::__construct(): Failed to parse time string (01/18/2016 00:00 AM America/New_York) at position 17 (A): The timezone could not be found in the database
Original PHP Code:
$datetime = new DateTime(trim(html_entity_decode($this->input->post('publish_date').' '.$_POST['schedule_time'].' '.$_POST['schedule_meridian'] . ' ' .$_POST['schedule_timezone'])));
$date = $datetime->format('D, d M Y H:i:s O');
I afraid you've created DateTime object like this:
$date = new DateTime('01/18/2016 00:00 AM America/New_York');
That is not a supported /valid datetime format!
If you want to create a DateTime object from another format you must call DateTime::createFromFormat() instead, look:
$timezone = new DateTimeZone('America/New_York');
$strdate = '01/18/2016 00:00 AM';
$date = DateTime::createFromFormat('m/d/Y H:i A', $strdate, $timezone);
PHP doc states:
DateTime::createFromFormat / date_create_from_format — Returns new DateTime object formatted according to the specified format
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.