2

So I have a dictionary called match. This has details of a match and one of the keys are game_time. If the game time is <= 10, the match is in draft. Else, I want to report the game time but the value its stored in is just in seconds.


                    {% if match.game_time <= 10 %}
                        drafting
                    {% else %}
                        {{match.game_time|date: "Z"}}
                    {% endif %}

Just gives me an error

Could not parse the remainder: ': "Z"' from 'match.game_time|date: "Z"'

any help appreciated

3 Answers3

3

Use this formate for time

{{your_date_field|time:"h:i a"}}
pranjal0819
  • 270
  • 2
  • 17
1
from datetime import datetime, timedelta


def millisec_to_time(millisec):
    d = datetime(1, 1, 1)+millisec
    if d.day - 1 == 0:
        return "{0}:{1}:{2}".format(d.hour, d.minute, d.second)
    else:
        return "{0}:{1}:{2}:{3}".format(d.day-1, d.hour, d.minute, d.second)

Try this to convert sec/msec to actual time.

0

If you install mathfilters, add it to your install_apps, and load it into your template then you can do this.

{{ booking.duration|div:3600|floatformat:"2" }}
Clarius
  • 1,183
  • 10
  • 10