Reputation:
I have that datetime : 2021-10-12T16:00:00.000+02:00
so I tried that :
import datetime
a = datetime.datetime.strptime("2021-10-12T16:00:00.000+02:00", '%Y-%m-%dT%H:%M:%SZ')
But it does not work I got that
ValueError: time data '2021-10-12T16:00:00.000+02:00' does not match format '%Y-%m-%dT%H:%M:%SZ'
Could you help me please ?
Thank you very much !
Upvotes: 0
Views: 172
Reputation: 2419
import datetime
a = datetime.datetime.strptime("2021-10-12T16:00:00.000+02:00", '%Y-%m-%dT%H:%M:%S.%f%z')
You're formatting it wrong.
%f
separated by a .
Z
; it has to be %z
Upvotes: 1
Reputation: 1
from datetime import datetime
today=datetime.now() /// 2021-06-25 07:58:56.550604
dt_string = now.strftime("%d/%m/%Y %H:%M:%S") /// 25/06/2021 07:58:56
Upvotes: -2
Reputation: 16951
This is an ISO date. The easiest way to parse it is to call fromisoformat
.
>>> datetime.datetime.fromisoformat("2021-10-12T16:00:00.000+02:00")
datetime.datetime(2021, 10, 12, 16, 0, tzinfo=datetime.timezone(datetime.timedelta(seconds=7200)))
Upvotes: 3