【问题标题】:How to get the age of a tweet?如何获取推文的年龄?
【发布时间】:2012-04-12 16:58:54
【问题描述】:

我正在使用 Search 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"
    }

我怎样才能获得该特定推文的年龄,以便在我的页面上打印出类似4m ago 的内容?那,created_at 字符串看起来一团糟!有什么简单的方法吗?

【问题讨论】:

标签: javascript twitter


【解决方案1】:

日期格式是标准的。

只需从中构造一个 Date 对象,然后根据需要对其进行操作。

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-20
    • 2023-02-15
    • 2017-02-21
    相关资源
    最近更新 更多