Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 719
Ardeus Avatar asked Dec 15 '22 08:12

Ardeus


2 Answers

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'); 
like image 92
Benz Avatar answered Dec 27 '22 10:12

Benz


try this

$date = '2013-07-09T04:58:23.075Z';
$seconds = strtotime($date);

echo date('Y-m-d [H:i:s]', $seconds);

Hope it helps!

like image 24
Lucas Lim Avatar answered Dec 27 '22 10:12

Lucas Lim