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

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

报告相同问题?

悬赏问题

  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分