【问题标题】:Using PRAW to call Reddit API. Need help interpreting the created datetime returned使用 PRAW 调用 Reddit API。需要帮助解释返回的创建日期时间
【发布时间】:2016-02-19 03:05:01
【问题描述】:

将鼠标悬停在“2个月前提交”后,我可以在reddit UI上获取帖子的创建日期。

就我而言,我正在查看的帖子有这个日期时间: 2015 年 12 月 18 日星期五 02:06:06 UTC

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

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

请帮忙!

【问题讨论】:

  • 这是一个unix timestamp,需要转换成可读的日期。
  • 你在用python吗?
  • 是的!我正在使用 python
  • 在下面查看我的答案。

标签: reddit praw


【解决方案1】:

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

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

示例用法:

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

希望这会有所帮助!

【讨论】:

  • 没问题!很高兴我能帮上忙。
猜你喜欢
  • 2012-06-13
  • 1970-01-01
  • 2022-01-06
  • 2012-12-04
  • 2017-11-02
  • 2012-09-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多