bobthegoalie bobthegoalie - 17 days ago 6
PHP Question

Convert String (ISO) to Date PHP

I am trying to convert a string to a date in

PHP
. The string I receive is formatted:-

"2016-07-16T1:22:04.324+1030"


OR

"2016-12-20T03:24:59.000Z"


When I try this

$newDate = DateTime::createFromFormat("c", $exp);
$expirationDate = $newFormat->getTimestamp();


DateTime
fails. Even when I try

$newDate = DateTime::createFromFormat(ISO8601, $exp;
$expirationDate = $newFormat->getTimestamp();


DateTime
still fails.

Any suggestions are greatly appreciated.

Answer

You can try like this:-

<?php

$time = "2016-07-16T1:22:04.324+1030";

echo date("d M, Y",strtotime(date($time)));

?>

Output:- 16 Jul, 2016 :- https://eval.in/594695

Reference taken:-

Converting ISO 8601 format to d M Y in PHP

Note:- you can change format of date according to your convenience. like D M d Y h:i:s O T . I checked this code on PHP 5.5.4 , PHP 5.5.14, PHP 7