1 2 3 4 5 6 7 8 9 10 11 12 13 14 | from django import template
from dateutil import tz
import datetime
register = template.Library()
@register.filter
def timeto(value):
now = datetime.datetime.now(tz.tzutc())
diff = value.astimezone(tz.tzutc()) - now
minutes = diff.seconds / 60
hours = minutes / 60
mins = minutes - (hours * 60)
return '%dhr %dmin' % (hours, mins)
|
More like this
- isoutc template filter by japerk 4 years, 1 month ago
- FuzzyDateTimeField by japerk 4 years, 1 month ago
- UTC DateTime field by ludo 5 years, 9 months ago
- JSON encode ISO UTC datetime by japerk 4 years, 1 month ago
- Natural language date/time form fields by jdriscoll 5 years, 11 months ago
Comments