gpt4 book ai didi

php - 使用 PHP 打印 JSON 时间戳格式

转载 作者:行者123 更新时间:2023-11-28 23:52:42 24 4
gpt4 key购买 nike

我想要这个输出用于我的 JSON,我如何使用 PHP 做这个时间戳格式?

 **This 1403375851930 is not equal to 2015-09-03 11:40:46**

{"newsfeed":[{"timeStamp": "1403375851930}]}"

这是我的当前输出

{"newsfeed":[{"timestamp":"2015-09-03 11:40:46"}]}

我的 PHP 代码

<?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;
}
?>

输出(时间戳在最后)

{"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"}]}

最佳答案

实现你的目标的最简单方法是:

$timestamp = strtotime('2015-09-03 11:40:46');

在你的情况下:

while ($row = mysql_fetch_array($result)) {
$row['timestamp'] = strtotime($row['timestamp']);
$json['newsfeed'][] = $row;
}

关于php - 使用 PHP 打印 JSON 时间戳格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32380359/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com