Parsing a string into a datetime object
mspetrovic at gmail.com
Sun Jan 25 01:10:39 CET 2009
On Jan 24, 10:56 am, Hrvoje Niksic <hnik... at xemacs.org> wrote:
> "Mark.Petrovic" <mspetro... at gmail.com> writes:
> > Might someone comment on why %f is not accepted as a valid field
> > directive in:
> >>>> from datetime import datetime
> >>>> created="2009-01-24 16:04:55.882788"
> >>>> dt = datetime.strptime(created,"%Y-%m-%d %H:%M:%S.%f")
> > Traceback (most recent call last):
> > File "<stdin>", line 1, in <module>
> > File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/
> > python2.5/_strptime.py", line 321, in strptime
> > (bad_directive, format))
> > ValueError: 'f' is a bad directive in format '%Y-%m-%d %H:%M:%S.%f'
> > This is for Python 2.5.1 under OS X.
> time.strptime is documented to use the same set of directives as
> time.strftime, andhttp://docs.python.org/library/time.html#time.strftimedoesn't mention
> a %f directive.
Thank you for the timely reply.
I guess I got mixed up by looking at the Python 2.6.1 docs, but used
the Python 2.5.1 interpreter:
wherein datetime.html does show the availability of the %f directive
(if I'm reading all this correctly).
More information about the Python-list