douhoujun9304 2015-01-03 00:05
浏览 74
已采纳

具有特定日期/时间的DateTime :: createFromFormat问题

I have been using the following code for a couple of months and it's been working fine, but now seems to have an issue with a certain time or time range. I have a GPS tracker that sends it's date/time like this: 150102235335

The format is ymdhis

$input_array[6] = 150102235335;
$datetime = DateTime::createFromFormat('ymdhis', $input_array[6]);
$datetime = $datetime->format('Y-m-d h:i:s');

Using that time, php crashes with the following error: PHP Fatal error: Call to a member function format() on a non-object

It seems that datetime ends up empty. However, using the time 150103004933 works just fine.

Can anyone see where I have gone wrong here, or is this a bug? Is there a better way to accomplish my date conversion? I am using PHP 5.4.35

  • 写回答

1条回答 默认 最新

  • douzhao7445 2015-01-03 00:16
    关注

    h is 12-hour format; and therefore 23 hours is invalid. Only values in the range 00-11 would be valid.

    H is 24-hour format

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部