How to convert date?

In turn gradually comes date type "2017-02-16T14:43:42+03:00"
it is necessary to convert the "day-month-year" automatically
The number of dates unknown

Just need a way to convert the date
March 20th 20 at 11:52
2 answers
March 20th 20 at 11:54
The strangest method I came up with. But seems to work), And cool:
date = "2017-02-16T14:43:42+03:00"
new_date = date.replace("T", " ")
new_date = "-".join(new_date[:10].split("-")[::-1]) + new_date[10:]
Read something about
datetime.strptime and strftime and everything will be great =) - Cleve34 commented on March 20th 20 at 11:57
@Torrey.Hahn, I once not they worked when I wrote the code on the ) - jalyn commented on March 20th 20 at 12:00
@Torrey.HahnThat something is not working - April_Stamm commented on March 20th 20 at 12:03
import datetime as dt
ds = "2017-02-16T14:43:42+03:00"
#zone only to find out that the cut not to do
date = dt.datetime.strptime(ds[:-6],"%Y-%m-%dT%H:%M:%S")
print(date.strftime("%d-%M-%Y %H:%M:%S"))
#'16-43-2017 14:43:42'
- Cleve34 commented on March 20th 20 at 12:06
March 20th 20 at 11:56
from datetime import datetime
src = "2017-02-16T14:43:42+03:00"
dt = datetime.strptime(src, "%Y-%m-%dT%H:%M:%S%z")
print(datetime.strftime(dt, "%d-%m-%Y %H:%M:%S"))

Find more questions by tags Python