ISO8601-Datetime in Python parsen
English
Deutsch
The easiest way to parse a ISO8601 timestamp like 2019-05-29T19:50:55.463+02:00 is to install the maya library using e.g.
install_maya.sh
pip install -U mayaFalls du noch Python2 verwendest, verwende pip2 anstelle von pip.
Nach der Installation von maya, verwende es so:
parse_iso8601_example.py
import maya
result = maya.parse('2019-05-29T19:50:55.463+02:00').datetime()
# Ergebnis ist ein Standard-datetime-Objekt!
print(result)Dies wird ausgeben
parse_iso8601_output.txt
2019-05-29 17:50:55.463000+00:00Beachte, wie der ursprüngliche Timestamp aus der Zeitzone +02:00 automatisch in ein UTC-datetime-Objekt konvertiert wird.
maya kann viele verschiedene Formate parsen, z.B.
parse_iso8601_examples.py
print(maya.parse('2019-05-29T19:50:55+02:00').datetime()) # Keine Bruchsekunden
print(maya.parse('2019-05-29T19:50:55').datetime()) # Keine Zeitzone (UTC angenommen)
print(maya.parse('2019-05-29 19:50:55').datetime()) # Nicht ISO8601
print(maya.parse('2019-05-29').datetime()) # 00:00:00 # 00:00:00 & UTC assumed UTC angenommenCheck out similar posts by category:
Python
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow