Reputation: 314
I want this output for my JSON, How can I do this timestamp format using PHP?
**This 1403375851930 is not equal to 2015-09-03 11:40:46**
{"newsfeed":[{"timeStamp": "1403375851930}]}"
this is my Current Output
{"newsfeed":[{"timestamp":"2015-09-03 11:40:46"}]}
my PHP Code
<?php
$query = 'SELECT * FROM newsfeed';
//execute the query using mysql_query
$result = mysql_query($query);
//then using while loop, it will display all the records inside the table
while ($row = mysql_fetch_array($result)) {
$json['newsfeed'][] = $row;
}
?>
Output(the timestamp is in the last)
{"newsfeed":[{"0":"54","id":"54","1":"55e869fe755ea8.63620266","unique_id":"55e869fe755ea8.63620266","2":"News and Events","type":"News and Events","3":"Cosmos","title":"Cosmos","4":"http:\/\/brmhelpdesk.comlu.com\/BRMhelpdesk\/uploads\/cosmos.jpg","image":"http:\/\/brmhelpdesk.comlu.com\/BRMhelpdesk\/uploads\/cosmos.jpg","5":"asd'[sajfpsdgfg\r\nfdfhfgkljghhdsf\r\nasfdjkhjlkjghjhsdfa\r\nasfgfdgjjlkjhgsffsad","description":"asd'[sajfpsdgfg\r\nfdfhfgkljghhdsf\r\nasfdjkhjlkjghjhsdfa\r\nasfgfdgjjlkjhgsffsad","6":"http:\/\/www.brmhelpdesk.comlu.com\/BRMhelpdesk\/uploads\/lugo.png","profilePic":"http:\/\/www.brmhelpdesk.comlu.com\/BRMhelpdesk\/uploads\/lugo.png","7":"2015-09-03 11:40:46","timestamp":"2015-09-03 11:40:46"}]}
Upvotes: 1
Views: 449
Reputation: 408
The easiest way to achieve what do you is this :
$timestamp = strtotime('2015-09-03 11:40:46');
In your case :
while ($row = mysql_fetch_array($result)) {
$row['timestamp'] = strtotime($row['timestamp']);
$json['newsfeed'][] = $row;
}
Upvotes: 1