Zoker
Zoker

Reputation: 2059

Convert json timestamp with php

I have a string that contains a "json timestamp" (I guess its called so, because of this question: The "right" JSON date format)

2015-08-11T09:19:25Z

Now I want to convert this string with php into something like this:

09:19 11.08.2015

I tried the date function, but it did not work.

Upvotes: 0

Views: 3454

Answers (2)

Jiri Zachar
Jiri Zachar

Reputation: 597

if you want use date function from PHP, you must set correct timezone:

date_default_timezone_set('America/New_York');
var_dump(date("H:i d.m.Y", strtotime('2015-08-11T09:19:25Z'))); 

Upvotes: 0

baao
baao

Reputation: 73211

You can use DateTime to convert an ISO date to a format you want:

$a = new \DateTime("2015-08-11T09:19:25Z");
$b = $a->format('H:i d.m.Y');
var_dump($b);

Upvotes: 5

Related Questions