djangotimefield

TimeField format in Django


I am trying to use a TimeField model which only consists of MM:SS.xx (ie 43:31.75) format. Is it possible to format a regular Python time object like this?

Thanks.


Solution

  • Absolutely, you can find it in the datetime module here.

    http://docs.python.org/release/2.5.2/lib/datetime-time.html

    >>> from datetime import time
    >>> time_obj = time(0, 43, 31, 750000)
    datetime.time(0, 43, 31, 750000)
    >>> time_obj.strftime('%M:%S.%f')
    '43:31.750000'