[Python] Python 3 Convert ISO 8601 to milliseconds

Discussão em 'Python' iniciado por Stack, Junho 27, 2025.

  1. Stack

    Stack Membro Participativo

    I'm receiving an ISO 8601 format from an API GET request ("2020-02-25T00:02:43.000Z"). I'm trying to convert it to milliseconds, because that format is required in the payload of the API POST call. I've been successful running the code from a Linux system, but I get ValueError: Invalid format string from Windows.

    From Linux:

    import dateutil.parser

    time = "2020-02-25T00:02:43.000Z"
    parsed_time = dateutil.parser.parse(time)
    t_in_millisec = parsed_time.strftime('%s%f')
    t_in_millisec[:-3]


    returns

    '1582588963000'


    From Windows:

    import dateutil.parser

    1 time = "2020-02-25T00:02:43.000Z"
    2 parsed_time = dateutil.parser.parse(time)
    ----> 3 t_in_millisec = parsed_time.strftime('%s%f')

    ValueError: Invalid format string


    Is there a way around this?

    Continue reading...

Compartilhe esta Página