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

Daryl V vandyke.geospatial at gmail.com
Fri Feb 17 02:29:46 CET 2012

You've gotten some really excellent advice about how to approach working
with the time format.  Here's a chunk of code I use quite a bit.  It's
probably sub-optimal, but playing with it might help you come up with a
solution that works for your application.

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

def TimeStampMaker():
    import datetime
    t = datetime.datetime.now()
    strTmonth = Int2Digit(t.month)
    strTday = Int2Digit(t.day)
    strThour = Int2Digit(t.hour)
    strTminute = Int2Digit(t.minute)
    timeStamp = str(t.year)+strTmonth+strTday+strThour+strTminute
    return timeStamp

Good Luck -  D
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20120216/d239a846/attachment.html>

More information about the Tutor mailing list