douzhanglu4591
2014-06-19 19:11
浏览 53
已采纳

转换日期保持失败dd / mm / yyyy HH:ii

I'm desperately looking to convert my date to Y-m-d H:i My date: 19/06/2014 09:30

I tried this:

$show_date = DateTime::createFromFormat('d/m/Y', $dateValue)
    ->format('Y-m-d');

But this will give the error: Fatal error: Call to a member function format() on a non-object

I tried with the Procedural style, yet that doesn't work.

date('Y-m-d H:i', strtotime(dateValue));

I tried some other stuff and nothing seems to work. Can't even convert it to unix. Anyone has an idea?

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dotws86260 2014-06-19 19:13
    已采纳

    You have to account for the time when using DateTime::createFromFormat() even if you don't want it when you format the date later:

    $show_date = DateTime::createFromFormat('d/m/Y H:i', $dateValue)->format('Y-m-d');
    

    Demo

    已采纳该答案
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题