def html_date(value, displayfmt=None, datetimefmt='c', **kwargs):
"""Format a date and wrap it in a html <time> element.
Additional html attributes may be provided as kwargs (e.g. 'class').
Note: Converts the value to localtime as we loose the expects_localtime
flag functionality by directly calling the date filter from django.
"""
localtime_value = timezone.localtime(value)
displaydate = defaultfilters.date(localtime_value, displayfmt)
datetime = defaultfilters.date(localtime_value, datetimefmt)
attribs = flatatt(kwargs)
result = '<time %s datetime="%s">%s</time>' % (attribs,
datetime,
displaydate)
return mark_safe(result)
评论列表
文章目录