[Python] Python: convert string to datetime object failed if the format is with comma

Discussão em 'Python' iniciado por Stack, Março 31, 2025.

  1. Stack

    Stack Membro Participativo

    So i try to convert my string to date time object without knowing the format this way:

    date = '019-03-13 17:35:35.855'
    date_object = datetime.fromisoformat(date)


    So this works fine but in case the datetime object failed if the format is with comma this fail:

    date = '019-03-13 17:35:35,855'
    date_object = datetime.fromisoformat(date)


    ValueError: Invalid isoformat string: '2019-03-13 17:35:35,855'
    ​

    And most of my files written with this comma format.

    Any suggestions ?

    Continue reading...

Compartilhe esta Página