Re: why not datetime.strptime() ?

Discussion in 'Python' started by Skip Montanaro, Jan 7, 2005.

  1. 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.

    If someone wants to get their feet wet with extension module programming
    this might be a good place to start. Mostly, I think nobody who has
    needed/wanted it so far has the round tuits available to spend on the task.

    Skip
     
    Skip Montanaro, Jan 7, 2005
    #1
    1. Advertising

  2. Skip Montanaro

    Lee Harr Guest

    On 2005-01-07, Skip Montanaro <> 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)
     
    Lee Harr, Jan 8, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. josh

    why not datetime.strptime() ?

    josh, Jan 7, 2005, in forum: Python
    Replies:
    0
    Views:
    300
  2. Joshua Spoerri

    Re: why not datetime.strptime() ?

    Joshua Spoerri, Jan 11, 2005, in forum: Python
    Replies:
    1
    Views:
    338
    David M. Cooke
    Jan 11, 2005
  3. Mr. SweatyFinger
    Replies:
    2
    Views:
    2,072
    Smokey Grindel
    Dec 2, 2006
  4. kongkolvyu
    Replies:
    4
    Views:
    491
    Old Wolf
    Jan 4, 2006
  5. Tuomas Vesterinen

    Problems with datetime.datetime.strptime

    Tuomas Vesterinen, May 9, 2009, in forum: Python
    Replies:
    0
    Views:
    887
    Tuomas Vesterinen
    May 9, 2009
Loading...

Share This Page