Namitha Janardhanan
Namitha Janardhanan

Reputation: 23

How to convert date/time to YYYY-MM-DDTHH:mm:ss.000+000 format?

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

Upvotes: 0

Views: 118

Answers (1)

payloc91
payloc91

Reputation: 3809

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.

Upvotes: 1

Related Questions