Reputation: 69
I am converting a date in the string to datetime object like this
datetime_object = datetime.strptime('2019-07-01T07:52:48.337-0700', '%Y-%m-%dT%H:%M:%S.%f-%Z')
Here I'm not understanding what the 0700
is?
Is it timezone? Isn't %Z
or %z
the right directive for that?
Upvotes: 0
Views: 61
Reputation: 81594
The -
is part of the timezone offset -0700
(the %z
directive, lowercase z), you should not have it in the format string:
datetime_object = datetime.strptime('2019-07-01T07:52:48.337-0700',
'%Y-%m-%dT%H:%M:%S.%f%z') # no - between %f and %z
%Z
(uppercase Z) is for timezone name (UTC, EST, etc..)
Upvotes: 1