人类可读的日期时间增量
human-datetimedelta的Python项目详细描述
示例:
from datetime import datetime, timedelta now = datetime.now() an_hour_ago = now - timedelta(hours=1) yesterday = now - timedelta(days=1) tomorrow = now + timedelta(days=1) import human print human.date(now) # 'now' print human.date(an_hour_ago) # 'an hour ago' print human.date(an_hour_ago, short=True) # '1h ago' print human.date(an_hour_ago, asdays=True) # 'today' print human.date(yesterday, short=True) # 'yest' print human.date(tomorrow) # 'tomorrow'