changing format of time duration.
Gabriel Genellina
gagsl-py2 at yahoo.com.ar
Sat Jun 5 04:03:25 EDT 2010
On 4 jun, 06:14, "Günther Dietrich" <gd.use... at spamfence.net> wrote:
> GabrielGenellina<gagsl-... at yahoo.com.ar> wrote:
> >Try the strptime method with a suitable format, like this (untested):
> >delta = now2-now1
> >delta.strftime('%H:%M:%S.%f')
>
> Throws an exception:
>
> |Traceback (most recent call last):
> | File "<stdin>", line 1, in <module>
> |AttributeError: 'datetime.timedelta' object has no attribute 'strftime'
>
> What seems logical, since the documentation doesn't mention an strftime
> method for timedelta.
You're right. Second try (still untested):
def nice_timedelta_str(d):
result = str(d)
if result[1] == ':':
result = '0' + result
return result
delta = now2-now1
print nice_timedelta_str(delta)
--
Gabriel Genellina
More information about the Python-list
mailing list