A simple calculation python source code expiration time

The development process is preferably up piece of content recording, content segment content below about python simple calculation of the expiration time, should also benefit everyone.

def time_passed(value):
    now = datetime.now()
    past = now - value
    if past.days:
        return u'%s天前' % past.days
    mins = past.seconds / 60
    if mins < 60:
        return u'%s分钟前' % mins
    hours = mins / 60
    return u'%s小时前' % hours

Guess you like

Origin blog.51cto.com/14389287/2432519