4

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.

4 Answers 4

10

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'); 
Sign up to request clarification or add additional context in comments.

3 Comments

It seems it works. it knows because of 75Z mean 75 minutes from UTC or GMT sort of time?
@Ardeus The .075 is 75 microseconds and the Z (pronounced Zulu) indicates the time is in UTC.
.075 is miliseconds (not microseconds).
2

try this

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

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

Hope it helps!

1 Comment

And what about the timezone?
1
$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.

Comments

-1

@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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.