douhoujun9304 2015-01-03 08: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 08: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

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

报告相同问题?

悬赏问题

  • ¥20 delta降尺度方法,未来数据怎么降尺度
  • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效
  • ¥15 再不同版本的系统上,TCP传输速度不一致
  • ¥15 高德地图点聚合中Marker的位置无法实时更新
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程