Graph api gives json format data, here is the url we taking
https://graph.facebook.com/valid_user_id/feed?access_token=some_valid_access_token
This url of graph api return json format date like this
"data": [ { "id": "344128252278047_552656441425226", "from": { "category": "Athlete", "name": "Sachin Tendulkar", "id": "344128252278047" }, "message": "Childhood click.", "picture": "http://photos-a.ak.fbcdn.net/hphotos-ak-ash4/487885_552656431425227_822007316_s.jpg", "link": "https://www.facebook.com/photo.php?fbid=552656431425227&set=a.402901949734010.98326.344128252278047&type=1&relevant_count=1", "icon": "http://static.ak.fbcdn.net/rsrc.php/v2/yz/r/StEh3RhPvjk.gif", "actions": [ { "name": "Comment", "link": "https://www.facebook.com/344128252278047/posts/552656441425226" }, { "name": "Like", "link": "https://www.facebook.com/344128252278047/posts/552656441425226" } ], "privacy": { "value": "" }, "type": "photo", "status_type": "added_photos", "object_id": "552656431425227", "created_time": "2013-02-13T05:56:11+0000", "updated_time": "2013-02-13T05:56:11+0000", "shares": { "count": 2802 }, "likes": { "data": [ { "name": "Tanmay Bibave", "id": "100003692878321" }, { "name": "Niranjan Ravikumar", "id": "100000410376292" }, { "name": "Anik Sarma", "id": "100001882359476" }, { "name": "Alok Joshi", "id": "100001626819135" } ], "count": 50882 }, "comments": { "count": 1539 } },
Here is the code after fetching the create time and converted into seconds
function formatDateTime(dateStr){ var year, month, day, hour, minute, dateUTC, date, ampm, d, time; var iso = (dateStr.indexOf(' ')==-1&&dateStr.substr(4,1)=='-'&&dateStr.substr(7,1)=='-'&&dateStr.substr(10,1)=='T') ? true : false; year = dateStr.substr(0,4); month = parseInt((dateStr.substr(5,1)=='0') ? dateStr.substr(6,1) : dateStr.substr(5,2))-1; day = dateStr.substr(8,2); hour = dateStr.substr(11,2); minute = dateStr.substr(14,2); dateUTC = Date.UTC(year, month, day, hour, minute); date = new Date(dateUTC); var curDate = new Date(); var currentStamp = curDate.getTime(); var datesec = date.setUTCSeconds(0); var difference = parseInt((currentStamp - datesec)/1000); return difference; }
calling code
var abc =formatDateTime(data[k].created_time); console.log(abc);
Here you pass in date[k].created_time = 2013-02-13T05:56:11+0000
Be the first to comment.