views:

60

answers:

4

In Django template language I can display a time with microseconds using :

{{ player.time_to_display|time:"i:s:u" }}

I would like to display only milliseconds instead of the full microsecond value. I am not able to locate a way to do that in the documentation, is there a simple mean to do that ?

+1  A: 

What about dividing your microseconds by 1000 (and maybe round the new value off)?

1000 microsecons = 1 millisecond.

Sebastian
Ok I will go the route of implementing a new custom filter.
Whirly
+2  A: 

There is no built in support for displaying milliseconds in Django, or in Python for that matter. Your best bet would be to implement a custom filter that accepts a datetime instance and do the conversion yourself.

Manoj Govindan
A: 

Try the following:

{{ player.time_to_display|time:"i:s" }}:{{ player.time_to_display|time:"u"|slice:":3" }}

This separates milliseconds and takes just 3 first letters. However it does not do rounding - but do you really need it at such tiny values?

dmitko
A: 

Thanks it is perfect. I am currently doing a 3D snowboard game under Facebook and 5 digits were really too much :)

Whirly