1

I got a JSON response of date and time in string format, and I want it to convert into proper date and time. I'm using a API to get a response and that comes in JSON code, but while it is in string form. How can I convert it into Proper Date and Time.

I got following response:

"start_time": 1492841592,
"end_time": 1492841619,
"seconds": 22392,
"duration": "00:00:27",
"_drm": 0.45,

And I want output in :

01:10pm 16 Mar

This format.

To convert it I'm trying to use date() function from PHP. But it wont give me proper result. I'm referred following question:

How to convert string to date format in PHP?

how to convert string day into date time format in php

how to convert String time to dateTime format in php?

Community
  • 1
  • 1
Ganesh Aher
  • 1,118
  • 3
  • 21
  • 51

1 Answers1

0

Are you looking for something like this?

$json = <<<'JSON'
{
  "start_time": 1492841592,
  "end_time": 1492841619,
  "seconds": 22392,
  "duration": "00:00:27",
  "_drm": 0.45
}
JSON;

$dt = json_decode($json);

echo date('h:ia M j', $dt->start_time);

Output:

06:13am Apr 22

Demo

peterm
  • 91,357
  • 15
  • 148
  • 157