2017-02-24 37 views
1

Prawを使用してコメントが投稿されてから時間を取得する方法はありますか?コメントが投稿されてからの時間を取得する[Praw]

私はドキュメントを見てきましたが、それについての言及が見つかりませんでした。そうでない場合、時間を得るための回避策がありますか?

答えて

0

あなたがまだ答えを探しているのであればわかりません。いずれにせよ、誰かが、検索エンジン経由でこれを見つけるかもしれないので、ここでアイデアです:

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 
を返し
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") 

関連する問題