Formatting for hh:mm:ss

Bjorn Pettersen pbjorn at uswest.net
Tue Dec 26 13:36:12 EST 2000


This should work (although it might be easier doing it directly...):

 def hms(secs):
  import time
  time_tuple = (0,0,0,0,0,secs,0,0,0)
  time_val = time.mktime(time_tuple)
  time_local = time.localtime(time_val)
  return time.strftime('%X', time_local)

-- bjorn


Roy Katz wrote:

> Hello,
>
> 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?
>
> Thanks,
> Roey




More information about the Python-list mailing list