why not datetime.strptime() ?

Lee Harr lee at example.com
Sat Jan 8 09:48:22 EST 2005


On 2005-01-07, Skip Montanaro <skip at pobox.com> wrote:
>
>     josh> Shouldn't datetime have strptime?
>
> Sure, but it's not quite as trivial to implement as was strftime() support.
> While strftime() is a C library function and thus easily called from within
> the datetime C code, strptime() is implemented in Python as part of the time
> module for portability (strptime(3) is not universally available).  You'd
> need to import the time module, call its strptime() function with the input
> string and format, then use the tuple it returns to initialize a new
> datetime object.
>


Not sure this is exactly related, but I was using datetime
the other day to make timestamps:

>>> import datetime
>>> ts = datetime.datetime.now().isoformat()
>>> ts
'2005-01-08T09:45:16.896805'


and figured there would be an easy way to reverse that.
Something along the lines of:
dt = datetime.datetime.fromisoformat(ts)



More information about the Python-list mailing list