Created
March 22, 2016 13:43
-
-
Save dantangfan/3c2424729d8880743b38 to your computer and use it in GitHub Desktop.
Revisions
-
dantangfan created this gist
Mar 22, 2016 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,19 @@ # coding:utf-8 # 将时间戳转换为时间差 def timeago(t): if not t: return "" if not isinstance(t, (int, long)): return t delta = int(time.time() - int(t)) if delta < 60: return u'刚刚' if delta < 3600: return u'%s分钟前' % (delta // 60) if delta < 86400: return u'%s小时前' % (delta // 3600) if delta < 604800: return u'%s天前' % (delta // 86400) dt = datetime.datetime.fromtimestamp(t) return u'%s年%s月%s日' % (dt.year, dt.month, dt.day)