Ardeus Ardeus - 4 months ago 10
PHP Question

PHP Parse Date From String

I received a date string from API respond like this


"2013-07-09T04:58:23.075Z"


How can I parse that string, say to change format to


2013-07-09 [04:58:23]


The time indeed is not based on my local time, I think the .075Z should change something about the time.

Thanks in advance for your help.

Answer

You can do that using the DateTime object.

$Date = new DateTime('2013-07-09T04:58:23.075Z'); //create dateTime object
$Date->setTimezone(new DateTimeZone('Europe/Amsterdam')); //set the timezone

echo $Date->format('d/m/Y H:i'); 
Comments