[Tutor] Formating from hhmms to hh:mm:ss
kent37 at tds.net
Mon Sep 8 03:57:36 CEST 2008
On Sun, Sep 7, 2008 at 9:33 PM, Wayne Watson
<sierra_mtnview at sbcglobal.net> wrote:
> Here's as far as I can go with this. The last line of output asks the
> question I need an answer for.
> (Once again my direct post to tutor at python.org has failed to appear here
> (sent 5:42 PDT), as before.)
It arrived late for some reason.
You can do what you want much more simply using datetime.strptime()
In : from datetime import datetime, timedelta
In : format = '%Y%m%d_%H%M%S'
In : d=datetime.strptime('20080321_113405', format)
In : d
Out: datetime.datetime(2008, 3, 21, 11, 34, 5)
In : d += timedelta(seconds=200)
In : d
Out: datetime.datetime(2008, 3, 21, 11, 37, 25)
In : d.strftime(format)
More information about the Tutor