代码之家  ›  专栏  ›  技术社区  ›  michaelmcgurk

用PHP格式化日期时间

php
  •  1
  • michaelmcgurk  · 技术社区  · 6 年前

    我的API以以下格式输出日期时间: 2018-06-17T09:07:00Z

    我该如何以更有意义的方式来展示这个,比如, 17/06/2018 .

    我看了一下手册: http://php.net/manual/en/datetime.formats.date.php 然而,仍然无法找到实现这一目标的方法。

    $eventStart = "2018-06-17T09:07:00Z";

    5 回复  |  直到 6 年前
        1
  •  1
  •   Sinto    6 年前

    您可以用php将其格式化为以下代码:

    echo date('d/m/Y', strtotime('2018-06-17T09:07:00Z'));
    
        2
  •  1
  •   Gaurav Kandpal    6 年前

    使用下面的代码。

    date('d/m/Y', strtotime('2018-06-17T09:07:00Z'));
    
        3
  •  1
  •   Dinesh Ghule    6 年前

    使用日期格式:

    $inputDate = "2018-06-17T09:07:00Z";
    echo date('d/m/Y', strtotime($inputDate));
    
        4
  •  1
  •   DsRaj    6 年前

    及时转换字符串,然后设置所需日期的格式

    Date-Format option

    $date = '2018-06-17T09:07:00Z';
    echo date('d/m/Y', strtotime($date));
    
        5
  •  1
  •   huks    6 年前

    设置日期格式,但首先将字符串转换为时间。

    echo date('d/m/Y', strtotime($inputDate));