quoth the Ognjen Bezanov: > I never thought id need help with such a thing as time formatting > (admittadly i never did it before) but ok, i guess there is a first for > everything. > > I have a float variable representing seconds, and i want to format it > like this: > > 0:00:00 (h:mm:ss) > > Now search as I might i am finding this quite elusive, i had a look at > the time module but that seems overly complicated for this. Anyone got > any simple solutions to doing this? cheers!
def printTime(seconds): hours = seconds / 3600 seconds = seconds - (hours * 3600) minutes = seconds / 60 seconds = seconds - (minutes * 60) print "%i:%s:%s" % (hours, str(minutes).zfill(2), str(seconds).zfill(2)) I am certainly no pro at python but this seems to do it for me. I am sure someone could write it much more elegantly. I am still a little confused as to how you have a float that represents seconds? This will only work if 'seconds' is an int ( al la ' 44342865') but maybe it could help you? -d -- darren kirby :: Part of the problem since 1976 :: http://badcomputer.org "...the number of UNIX installations has grown to 10, with more expected..." - Dennis Ritchie and Ken Thompson, June 1972
pgp6I7q4f3fVW.pgp
Description: PGP signature
-- http://mail.python.org/mailman/listinfo/python-list