0

How to convert DD-MM-YYYY to YYYY-MM-DDTHH:mm:ss.000+0000 format using Python.

I want to convert this

20-05-2022 14:03:02

to

2022-05-20T14:03:02.000+0000
Gino Mempin
  • 25,369
  • 29
  • 96
  • 135
  • Does this answer your question? [ISO time (ISO 8601) in Python](https://stackoverflow.com/questions/2150739/iso-time-iso-8601-in-python) – Gino Mempin Nov 17 '22 at 10:42

1 Answers1

1

Use the datetime module

from datetime import datetime, timezone

dtt = datetime.strptime("20-05-2022 14:03:02", "%d-%m-%Y %H:%M:%S")
print(dtt.replace(tzinfo=timezone.utc).isoformat(timespec="milliseconds"))

Prints 2022-05-20T14:03:02.000+00:00

See this answer for python datetime and ISO 8601.

payloc91
  • 3,724
  • 1
  • 17
  • 45