gpt4 book ai didi

php - 在数据库中找不到 DateTime 时区

转载 作者:可可西里 更新时间:2023-11-01 13:42:36 25 4
gpt4 key购买 nike

有没有人遇到过这个奇怪的问题?错误信息:

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

原始 PHP 代码:

$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');

最佳答案

恐怕您已经像这样创建了 DateTime 对象:

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

那不是 supported/有效的日期时间格式!

如果您想从另一种格式创建 DateTime 对象,您必须调用 DateTime::createFromFormat()相反,请看:

$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 文档指出:

DateTime::createFromFormat / date_create_from_format — Returns new DateTime object formatted according to the specified format

关于php - 在数据库中找不到 DateTime 时区,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34861317/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com