470,614 Members | 1,481 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,614 developers. It's quick & easy.

Formatting Time

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!
Jul 19 '05 #1
1 1626
Am Fri, 03 Jun 2005 09:29:41 +0100 schrieb 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)


Hi,

Does this work? (not well tested)

i=12009 # Number of seconds
res=[]
# d h, m
for d in [24*60*60, 60*60, 60]:
res.append("%02d" % (i/d))
i=i%d
res.append("%02d" % i)
print ":".join(res)
# --> 00:03:20:09 (d:h:m:s)

--
Thomas Güttler, http://www.thomas-guettler.de/
Jul 19 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by hope | last post: by
25 posts views Thread by mdh | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.