strptime dilemma with Python 2.5

pythonista sitecontactus at gmail.com
Sun May 30 12:13:02 EDT 2010


Hello,
I have a date string looking like the following:

 "Sun May 30 07:25:17 2010"

With Python 2.6, the %f is supported (it parses the microseconds), so
that this statement works:

    dt = datetime.strptime(s, "%a %b %d %H:%M:%f %Y")

However, with Python 2.5, (which is supported on the live Webfaction
server I'm using), %f is not supported.

 Is there a straightforward way to simply ignore the :17 microseconds
in the original string?

Maybe force it to "00" ? -  but without having to actually change the
original string by removing the ":17" ?

If I simply leave out the ":%f" in the strptime call, I get back a "
         ValueError: time data did not match format:  data=Sun May 30
19:33:54 2010  fmt=%a %b %d %H:%M %Y


Hoping for a simple solution that someone is familiar with
Thanks
Steve



More information about the Python-list mailing list