Python 3 konvertieren ISO 8601 in Millisekunden

Post a reply

Smilies
:) :( :oops: :chelo: :roll: :wink: :muza: :sorry: :angel: :read: *x) :clever:
View more smilies

BBCode is ON
[img] is ON
[flash] is OFF
[url] is ON
Smilies are ON

Topic review
   

Expand view Topic review: Python 3 konvertieren ISO 8601 in Millisekunden

by Anonymous » 17 Aug 2025, 11:31

Ich erhalte ein ISO 8601-Format aus einer API-GET-Anfrage ("2020-02-25T00: 02: 43.000z"). Ich versuche, es in Millisekunden umzuwandeln, da dieses Format bei der Nutzlast des API -Post -Calls erforderlich ist. Ich habe den Code erfolgreich aus einem Linux -System ausgeführt, aber ich erhalte ValueError: Ungültige Format -Zeichenfolge < /code> von Windows.

Code: Select all

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]
< /code>

Gibt < /p>

zurück'1582588963000'
< /code>

[b] Aus Windows: < /strong> < /p>

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
Gibt es einen Weg, um dies zu tun? [/b]

Top