使用 PRAW 调用 Reddit API。需要帮助解释返回的创建日期时间

Using PRAW to call Reddit API. Need help interpreting the created datetime returned

将鼠标悬停在 "submitted 2 months ago" 上后,我可以在 reddit UI 上获取 post 的创建日期 UI。

就我而言,我正在查看的 post 具有以下日期时间: 2015 年 12 月 18 日星期五 02:06:06 UTC

但是当我使用 praw 调用 reddit API 时,我在 created_utc 字段中得到了这个: 1450404366.0

我无法将 "Fri Dec 18 02:06:06 2015 UTC" 翻译成“1450404366.0”

请帮忙!

所以 reddit 给你的是一个 UNIX TIMESTAMP,它基本上是自 1970 年 1 月 1 日以来的秒数。(UTC)需要转换成人类可读的日期时间设置。

我建议使用 python 中的 datatime 模块:

用法示例:

import datetime
print(
    datetime.datetime.fromtimestamp(
        int("1284101485")
    ).strftime('%Y-%m-%d %H:%M:%S')
)

希望对您有所帮助!