du94414 2017-07-24 14:17
浏览 16

从字符串到php时间的日期和时间[重复]

This question already has an answer here:

Hi Im trying to get the string "25.01.2017 08:22:10" to a valid php time

date_default_timezone_set('Europe/Berlin');
$format = 'Y-m-d H:i:s';
$date = DateTime::createFromFormat($format, 25.01.2017 08:22:10);

does not work. Maybe its because of the dots...

</div>
  • 写回答

1条回答 默认 最新

  • douchi2022 2017-07-24 14:20
    关注

    Try this:

    date_default_timezone_set('Europe/Berlin');
    
    $date = DateTime::createFromFormat(
        'd.m.Y H:i:s', 
        '25.01.2017 08:22:10'
    );
    

    Note Adjusted the date format and surrounded the date with ' (it needs to be a string).

    For reference, see:

    评论

报告相同问题?

悬赏问题

  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?