Formatting for hh:mm:ss

Albert Hopkins ahopkins at
Tue Dec 26 21:07:30 CET 2000

On Tue, 26 Dec 2000 13:12:33 -0500, Roy Katz <katz at> wrote:
>I've searched the 'time' and 'locale' modules  for any function which
>would take a difference of two time.time()'s and format the result as
>hour:minutes:seconds, but I can't find any.  All I am doing is this:
>  t1 = time.time()
>  # some processing here
>  t2 = time.time()
>  total = t2 - t1
>  print_time( total )  
>where print_time() would format the time as above. Does anyone know if
>this function already exists?

It sounds to me that you can accomplish what you need with the 
time.strftime() function.  Of course you'll need to convert 'total' to a 
tuple to pass to the function.  Something like

def print_time(t)
	return time.strftime("%H:%M:%S", time.gmtime(t))

                                                     Albert Hopkins
                                             Sr. Systems Specialist
                                              Dynacare Laboratories 
                                              ahopkins at

-----= Posted via Newsfeeds.Com, Uncensored Usenet News =----- - The #1 Newsgroup Service in the World!
-----==  Over 80,000 Newsgroups - 16 Different Servers! =-----

More information about the Python-list mailing list