PHP Convert ISO date to more readable format?

前端 未结 7 922
长情又很酷
长情又很酷 2021-01-11 16:27

Just a simple question. How do I convert a PHP ISO time (like 2010-06-23T20:47:48-04:00) to something more readable? Is there a function already built in PHP? I\'ve looked a

相关标签:
7条回答
  • 2021-01-11 16:31

    For a short date try this:

    $a_date = '2010-06-23T20:47:48-04:00';
    echo date('Y-m-d', strtotime($a_date));
    
    0 讨论(0)
  • 2021-01-11 16:35

    I think you should try strftime

    http://php.net/function.strftime

    0 讨论(0)
  • 2021-01-11 16:37
    $format = "d M Y"; //or something else that date() accepts as a format
    date_format(date_create($time), $format);
    
    0 讨论(0)
  • 2021-01-11 16:42

    strptime() converts a string containing a time/date with the format passed as second argument to the function. The return value is an array containing values for day, month, year, hour, minutes, and seconds; you can use those values to obtain a string representing the date in the format you like.

    strptime() is available since PHP 5.1.0, while the class DateTime is available since PHP 5.2.0.

    0 讨论(0)
  • 2021-01-11 16:47

    Try this:

    echo date( "Y-m-d H:i:s", strtotime("2010-06-23T20:47:48-04:00") );
    

    Format this part "Y-m-d H:i:s" using format from this documentation http://php.net/manual/en/function.date.php

    0 讨论(0)
  • 2021-01-11 16:54

    Sounds like you're looking for the date function: http://php.net/function.date

    Possibly paired with the strtotime function: http://php.net/function.strtotime

    0 讨论(0)
提交回复
热议问题