datetime iso8601 string input

Peter Hansen peter at engcorp.com
Fri Feb 24 09:20:32 EST 2006


Rubic wrote:
> Thanks for your reply.  I wasn't clear in my
> prior post.  Rather than support the entire
> range of iso8601 formats, how about *just* the
> format that datetime emits?  Call it the
> parse_datetime() function.  Then it would be
> possible to take the output string of a datetime
> object and read it back in to round-trip the
> data.
> 
>     >>> now = str(datetime.datetime.now())
>     >>> now
>     '2006-02-24 06:58:23.737586'
>     >>> datetime.parse_datetime(now)
>     datetime.datetime(2006, 2, 24, 6, 58, 23, 737586)
> 
> Jeff Bauer
> Rubicon, Inc.

If that's truly all you want, then it's a near trivial function to 
write.  One of those "throw-away" functions you tend to whip up a few 
dozen times on every project, hardly noticing because you're using 
Python and it's so easy to do.

-Peter




More information about the Python-list mailing list