Question

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.

Was it helpful?

Solution

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'); 

OTHER TIPS

try this

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

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

Hope it helps!

$time = "2013-07-09T04:58:23.075Z";
$exp = explode('T',$time);
echo $exp[0] .' [' .substr($exp[1], 0, -5) . ']';

I'm using it like this.

@Benz

simply add below:

date_default_timezone_set('Australia/Brisbane');

echo date('d/m/Y H:i', strtotime('2013-07-09T04:58:23.075Z'));

were done! Hope this help.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top