【问题标题】:What is the best way to convert a string to time in php?在php中将字符串转换为时间的最佳方法是什么?
【发布时间】:2018-05-15 09:16:45
【问题描述】:

我有一个 MySQL 表,其中一个列中包含日期和时间作为文本 (15/05/2018 11:05:40)。我想将此字符串转换为 DateTime 格式,以便它可以用于根据 PHP 中的日期获取数据。

【问题讨论】:

  • DateTime DateTime::createFromFormat ( string $format , string $time [, DateTimeZone $timezone ] ) from the manual

标签: php string datetime


【解决方案1】:

使用DateTime::createFromFormat

$date = date_create_from_format('d/m/Y H:i:s', $time);

【讨论】:

    猜你喜欢
    • 2011-08-14
    • 1970-01-01
    • 2011-08-11
    • 1970-01-01
    • 2010-09-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多