Search code examples
phpw3c

How to convert w3c date to a custom format?


How do I to convert a w3c date to a custom format inside PHP?

My w3c date: "2015-02-26T03:11:41.000-03:00" My custom format: "dd/mm/YYYY hh:mm:ss"

Has someone Any idea?


Solution

  • How about this?

    $dateTime = new DateTime('2015-02-26T03:11:41.000-03:00');
    echo $dateTime->format('d/m/Y h:i:s');
    

    By using the codes above, it will output:

    26/02/2015 03:11:41
    

    It's always suggested to use DateTime class whenever available, which will have Exception to handle unable parsing cases.