i am using datetime.strptime()
in order to convert the timesatmp string received from the API to separate the date and time. one of the example :
from datetime import
datetime.strptime("2019-11-14T03:41:12.869000Z","%Y-%m-%dT%H:%M:%S.%f%
and I can't figure out what is wrong with this "2019-11-14T03:41:12.869000Z","%Y-%m-%dT%H:%M:%S.%f%Z"
?
CodePudding user response:
%Z
is Time zone name (empty string if the object is naive). for example UTC
. If trailing Z
appears in all your strings use Z
rather than %Z
, that is
import datetime
dt = datetime.datetime.strptime("2019-11-14T03:41:12.869000Z","%Y-%m-%dT%H:%M:%S.%fZ")
print(dt)
output
2019-11-14 03:41:12.869000
CodePudding user response:
Just remove the % before Z and it should work!
from datetime import datetime
datetime.strptime("2019-11-14T03:41:12.869000Z","%Y-%m-%dT%H:%M:%S.%fZ")