後人:這是我最終使用的。這是<app>/templatetags/datetime_filter.py
內容:
# -*- coding: utf-8 -*-
"""Application filter for `datetime`_ 24 hours.
.. _datetime: https://docs.python.org/2/library/datetime.html
"""
from django import template
from datetime import date, timedelta
register = template.Library()
@register.filter(name='format_datetime')
def format_datetime(value):
hours, rem = divmod(value.seconds, 3600)
minutes, seconds = divmod(rem, 60)
return '{}h {}m'.format(hours, minutes)
視圖
然後,補充一點:
{% load datetime_filter %}
[...]
{{ slice.day0|format_datetime }}