[Tutor] Time module

Norman Khine norman at khine.net
Tue Dec 4 15:51:27 CET 2007


Hello,
I am having difficulties in converting the following to display the 
difference that has passed in hours and seconds in a nice way.

from datetime import datetime
now = datetime.now()
posted = date
difference = now - posted

namespace['date'] = date
namespace['posted'] = difference

when I look at the 'posted' namespace I get

23:08:31.454767

What is the best way to split this so that it will show

'23h 08m 31s' ago

or

1d 23h 08m 31s ago

etc..

Thanks


More information about the Tutor mailing list