DateTime timezone not found in database

Has anyone else had this weird problem? Error message:

Fatal error: Throw an Exception exception with the message 'DateTime :: __ construct (): Failed to parse the time string (1/18/2016) 00:00 AM America / New_York) at position 17 (A): the time zone 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): time zone not found in 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 MYH:i:s O'); 
+2
source share
1 answer

I am afraid that you created a DateTime object as follows:

 $date = new DateTime('01/18/2016 00:00 AM America/New_York'); 

This is not a supported / valid datetime format!

If you want to create a DateTime object from a different format, you must call DateTime :: createFromFormat () , look:

 $timezone = new DateTimeZone('America/New_York'); $strdate = '01/18/2016 00:00 AM'; $date = DateTime::createFromFormat('m/d/YH:i A', $strdate, $timezone); 

PHP Document Status

DateTime :: createFromFormat / date_create_from_format - returns a new DateTime object formatted according to the specified format

+8
source

Source: https://habr.com/ru/post/1274466/


All Articles