看名字应该就知道是什么意思了,就是将时间转化成多少多少时间之前。很多网站都会用到的。
github 地址:https://github.com/hustcc/timeago 下面直接是 readme 内容。
发布到 pipy 了,直接 pip install timeago 即可体验。
timeago
A python lib format datetime to *** time ago.
Install
pip install timeago
Usage & Example
import timeago, datetime
now = datetime.datetime.now() + datetime.timedelta(seconds = 60 * 3.4)
print (timeago.format(date, now)) # will print 3 minutes ago
Methor & Parameter
only one API format.
Three parameters of method format:
date:datetimewill be done / format.now: reference time, must be instance ofdatetime.locale: the locale code, only zh_CN / en supported, defaulten.
Localization
- foke the project
- add <locale>.py file in the locales folder.
- pull a request.