2012-04-12 65 views
2

我使用的搜索API,並得到返回的JSON進口一些鳴叫:如何獲取推文的年齡?

"results": [ 
    { 
     "created_at": "Thu, 12 Apr 2012 04:58:01 +0000", 
     "from_user": "AdamHills", 
     "from_user_id": 23045431, 
     "from_user_id_str": "23045431", 
     "from_user_name": "Adam Hills", 
     "geo": null, 
     "id": 190302731255287800, 
     "id_str": "190302731255287808", 
     "iso_language_code": "sv", 
     "metadata": { 
      "result_type": "recent" 
     }, 
     "profile_image_url": "http://a0.twimg.com/profile_images/1350305654/goteborgs-rape_normal.jpg", 
     "profile_image_url_https": "https://si0.twimg.com/profile_images/1350305654/goteborgs-rape_normal.jpg", 
     "source": "<a href="http://twitter.com/#!/download/iphone" rel="nofollow">Twitter for iPhone</a>", 
     "text": "@Adde77 Den ska finnas tillgänglig i slutet av april.", 
     "to_user": "Adde77", 
     "to_user_id": 99782511, 
     "to_user_id_str": "99782511", 
     "to_user_name": "Adde P", 
     "in_reply_to_status_id": 190222715716763650, 
     "in_reply_to_status_id_str": "190222715716763648" 
    } 

我怎樣才能獲得特定的tweet的年齡,這樣我就可以打印出類似4m ago我的網頁上?那created_at字符串看起來一團糟!有沒有簡單的方法?

+1

檢查此代碼以瞭解它是如何完成的https://github.com/jzaefferer/jquery-prettydate/blob/master/jquery.prettydate.js – GillesC 2012-04-12 09:08:08

回答

2

日期格式是標準的。

只需從中構建一個Date對象,然後按照您的意願操作它。

var tweet_date = new Date("Thu, 12 Apr 2012 04:58:01 +0000");