[Tutor] How to convert seconds to hh:mm:ss format

Alan Gauld alan.gauld at btinternet.com
Fri Feb 17 08:50:10 CET 2012


On 17/02/12 01:29, Daryl V wrote:

>   def Int2Digit(integer):
>      if integer < 9:
>          strInteger = "0"+str(integer)
>      else:
>          strInteger = str(integer)
>      return strInteger

Or using format strings:

def int2Digit(integer):
     return "%02d" % integer

Although this doesn't behave quite right for negative numbers.
But I suspect the function  above's handling of negatives is not 
strictly as intended either...

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/



More information about the Tutor mailing list