from datetime import datetime,time from django.utils.dateformat import DateFormat register = Library() @register.filter def humantime(t): now = datetime.now() if datetime.combine(now, time()) < t and t < datetime.combine(now + timedelta(1), time()): f = 'g:i a' elif now.year == t.year: f = 'M j' else: f = 'n/j/y' df = DateFormat(t) return df.format(f).replace('.m.', 'm')