changing format of time duration.

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Fri Jun 4 02:21:31 EDT 2010


On 3 jun, 17:24, dave <davidrey... at gmail.com> wrote:
> Quick question. I have to time stamps (now and now2).
>
> now = datetime.datetime.now();
> now2 = datetime.datetime.now();
>
> now2-now1 yields me a result in 0:00:00.11221 (H:MM:SS.ssss)
>
> I wanted to know if there is a standard python method or a quick hack
> to add an extra zero in the beginning.
>
> So the result I am looking for would be 00:00:00.11221

Try the strptime method with a suitable format, like this (untested):
delta = now2-now1
delta.strftime('%H:%M:%S.%f')

http://docs.python.org/library/datetime.html#strftime-strptime-behavior

--
Gabriel Genellina



More information about the Python-list mailing list