1
我試圖從帖子中打印評論的日期。Facebook API:無法打印出或轉換created_time日期
我從響應此JSON:
"created_time": {
"date": "2016-12-24 10:55:12.000000",
"timezone_type": 1,
"timezone": "+00:00"
}
我試圖通過JSON循環和打印日期將其轉換爲datetime:
$request = $this->fb_request($id, 'comments');
foreach($request["comments"] as $comm) {
$date = new DateTime($comm["created_time"]["date"]);
$date = date_format($date,"Y/m/d H:i:s");
echo $date;
}
,但它給了我這個錯誤:
Cannot use object of type DateTime as array
API本身不會以該格式返回數據。你在這裏的東西一定已經被轉化成了別的東西。 (錯誤消息表明此時您已經有一個DateTime對象。) – CBroe