自从发表评论以来得到时间[Praw]



自从使用Praw发布评论以来,是否有办法获得时间?

我已经查看了文档,但找不到任何提及,如果没有的话,是否有任何解决方法可以得到时间?

我不知道,如果您仍在寻找答案。无论如何,有人可能通过搜索引擎找到这一点,所以这是一个想法:

import praw
import datetime
reddit = praw.Reddit(...)
comment = reddit.comment(id="ctu29cb")
now = int(datetime.datetime.timestamp(datetime.datetime.today()))
then = int(comment.created)
delta = now - then
print("comment has been created with timestamp", then)
print("which means on", datetime.datetime.fromtimestamp(then).strftime('%Y-%m-%d %H:%M:%S'))
print("that was", delta, "seconds or", str(datetime.timedelta(seconds=delta)), "hours ago")

返回

comment has been created with timestamp 1438924830
which means on 2015-08-07 05:20:30
that was 69533363 seconds or 804 days, 18:49:23 hours ago

最新更新