Python parse with strptime - Month Day Hours:Minute:Seconds Year Timezone - Does not match format
I'm having issues parsing "Mar 3 03:00:04 2019 GMT" with python's (datetime.datetime.strptime). I can't figure out what the issue is. At first I thought it was because the day was not zero padded, but according to the docs I found that is not the case.
import datetime
datetime.datetime.strptime("%b %d %H:%M:%S %Y %Z", "Mar 3 03:00:04 2019 GMT")
I've tried removing and adding whitespace to the format string. I've also tried going without the timezone specifier to no luck. The format I'm trying to parse comes from the ssl socket method getpeercert
.
ValueError Traceback (most recent call last)
<ipython-input-14-a9f4aa24cc39> in <module>
----> 1 datetime.datetime.strptime("%b %d %H:%M:%S %Y %Z", "Mar 3 03:00:04 2019 GMT")
/usr/lib/python3.7/_strptime.py in _strptime_datetime(cls, data_string, format)
575 """Return a class cls instance based on the input string and the
576 format string."""
--> 577 tt, fraction, gmtoff_fraction = _strptime(data_string, format)
578 tzname, gmtoff = tt[-2:]
579 args = tt[:6] + (fraction,)
/usr/lib/python3.7/_strptime.py in _strptime(data_string, format)
357 if not found:
358 raise ValueError("time data %r does not match format %r" %
--> 359 (data_string, format))
360 if len(data_string) != found.end():
361 raise ValueError("unconverted data remains: %s" %
ValueError: time data '%b %d %H:%M:%S %Y %Z' does not match format 'Mar 3 03:00:04 2019 GMT'
What is the correct format string I should be using?
python datetime strptime
add a comment |
I'm having issues parsing "Mar 3 03:00:04 2019 GMT" with python's (datetime.datetime.strptime). I can't figure out what the issue is. At first I thought it was because the day was not zero padded, but according to the docs I found that is not the case.
import datetime
datetime.datetime.strptime("%b %d %H:%M:%S %Y %Z", "Mar 3 03:00:04 2019 GMT")
I've tried removing and adding whitespace to the format string. I've also tried going without the timezone specifier to no luck. The format I'm trying to parse comes from the ssl socket method getpeercert
.
ValueError Traceback (most recent call last)
<ipython-input-14-a9f4aa24cc39> in <module>
----> 1 datetime.datetime.strptime("%b %d %H:%M:%S %Y %Z", "Mar 3 03:00:04 2019 GMT")
/usr/lib/python3.7/_strptime.py in _strptime_datetime(cls, data_string, format)
575 """Return a class cls instance based on the input string and the
576 format string."""
--> 577 tt, fraction, gmtoff_fraction = _strptime(data_string, format)
578 tzname, gmtoff = tt[-2:]
579 args = tt[:6] + (fraction,)
/usr/lib/python3.7/_strptime.py in _strptime(data_string, format)
357 if not found:
358 raise ValueError("time data %r does not match format %r" %
--> 359 (data_string, format))
360 if len(data_string) != found.end():
361 raise ValueError("unconverted data remains: %s" %
ValueError: time data '%b %d %H:%M:%S %Y %Z' does not match format 'Mar 3 03:00:04 2019 GMT'
What is the correct format string I should be using?
python datetime strptime
The error is insightful:ValueError: time data '%b %d %H:%M:%S %Y %Z' does not match format 'Mar 3 03:00:04 2019
– jpp
Jan 2 at 18:26
Related: stackoverflow.com/q/38147923/771848
– alecxe
Jan 2 at 18:49
add a comment |
I'm having issues parsing "Mar 3 03:00:04 2019 GMT" with python's (datetime.datetime.strptime). I can't figure out what the issue is. At first I thought it was because the day was not zero padded, but according to the docs I found that is not the case.
import datetime
datetime.datetime.strptime("%b %d %H:%M:%S %Y %Z", "Mar 3 03:00:04 2019 GMT")
I've tried removing and adding whitespace to the format string. I've also tried going without the timezone specifier to no luck. The format I'm trying to parse comes from the ssl socket method getpeercert
.
ValueError Traceback (most recent call last)
<ipython-input-14-a9f4aa24cc39> in <module>
----> 1 datetime.datetime.strptime("%b %d %H:%M:%S %Y %Z", "Mar 3 03:00:04 2019 GMT")
/usr/lib/python3.7/_strptime.py in _strptime_datetime(cls, data_string, format)
575 """Return a class cls instance based on the input string and the
576 format string."""
--> 577 tt, fraction, gmtoff_fraction = _strptime(data_string, format)
578 tzname, gmtoff = tt[-2:]
579 args = tt[:6] + (fraction,)
/usr/lib/python3.7/_strptime.py in _strptime(data_string, format)
357 if not found:
358 raise ValueError("time data %r does not match format %r" %
--> 359 (data_string, format))
360 if len(data_string) != found.end():
361 raise ValueError("unconverted data remains: %s" %
ValueError: time data '%b %d %H:%M:%S %Y %Z' does not match format 'Mar 3 03:00:04 2019 GMT'
What is the correct format string I should be using?
python datetime strptime
I'm having issues parsing "Mar 3 03:00:04 2019 GMT" with python's (datetime.datetime.strptime). I can't figure out what the issue is. At first I thought it was because the day was not zero padded, but according to the docs I found that is not the case.
import datetime
datetime.datetime.strptime("%b %d %H:%M:%S %Y %Z", "Mar 3 03:00:04 2019 GMT")
I've tried removing and adding whitespace to the format string. I've also tried going without the timezone specifier to no luck. The format I'm trying to parse comes from the ssl socket method getpeercert
.
ValueError Traceback (most recent call last)
<ipython-input-14-a9f4aa24cc39> in <module>
----> 1 datetime.datetime.strptime("%b %d %H:%M:%S %Y %Z", "Mar 3 03:00:04 2019 GMT")
/usr/lib/python3.7/_strptime.py in _strptime_datetime(cls, data_string, format)
575 """Return a class cls instance based on the input string and the
576 format string."""
--> 577 tt, fraction, gmtoff_fraction = _strptime(data_string, format)
578 tzname, gmtoff = tt[-2:]
579 args = tt[:6] + (fraction,)
/usr/lib/python3.7/_strptime.py in _strptime(data_string, format)
357 if not found:
358 raise ValueError("time data %r does not match format %r" %
--> 359 (data_string, format))
360 if len(data_string) != found.end():
361 raise ValueError("unconverted data remains: %s" %
ValueError: time data '%b %d %H:%M:%S %Y %Z' does not match format 'Mar 3 03:00:04 2019 GMT'
What is the correct format string I should be using?
python datetime strptime
python datetime strptime
asked Jan 2 at 18:17
HSchmaleHSchmale
86721131
86721131
The error is insightful:ValueError: time data '%b %d %H:%M:%S %Y %Z' does not match format 'Mar 3 03:00:04 2019
– jpp
Jan 2 at 18:26
Related: stackoverflow.com/q/38147923/771848
– alecxe
Jan 2 at 18:49
add a comment |
The error is insightful:ValueError: time data '%b %d %H:%M:%S %Y %Z' does not match format 'Mar 3 03:00:04 2019
– jpp
Jan 2 at 18:26
Related: stackoverflow.com/q/38147923/771848
– alecxe
Jan 2 at 18:49
The error is insightful:
ValueError: time data '%b %d %H:%M:%S %Y %Z' does not match format 'Mar 3 03:00:04 2019
– jpp
Jan 2 at 18:26
The error is insightful:
ValueError: time data '%b %d %H:%M:%S %Y %Z' does not match format 'Mar 3 03:00:04 2019
– jpp
Jan 2 at 18:26
Related: stackoverflow.com/q/38147923/771848
– alecxe
Jan 2 at 18:49
Related: stackoverflow.com/q/38147923/771848
– alecxe
Jan 2 at 18:49
add a comment |
2 Answers
2
active
oldest
votes
datetime.datetime.strptime(date_string, format)
The exact syntax should be as above. Changing the order of arguments would work.
datetime.datetime.strptime("Mar 3 03:00:04 2019 GMT","%b %d %H:%M:%S %Y %Z")
datetime.datetime(2019, 3, 3, 3, 0, 4)
add a comment |
You need to flip the args, ie:
import datetime
datetime.datetime.strptime("Mar 3 03:00:04 2019 GMT", "%b %d %H:%M:%S %Y %Z")
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54011240%2fpython-parse-with-strptime-month-day-hoursminuteseconds-year-timezone-does%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
datetime.datetime.strptime(date_string, format)
The exact syntax should be as above. Changing the order of arguments would work.
datetime.datetime.strptime("Mar 3 03:00:04 2019 GMT","%b %d %H:%M:%S %Y %Z")
datetime.datetime(2019, 3, 3, 3, 0, 4)
add a comment |
datetime.datetime.strptime(date_string, format)
The exact syntax should be as above. Changing the order of arguments would work.
datetime.datetime.strptime("Mar 3 03:00:04 2019 GMT","%b %d %H:%M:%S %Y %Z")
datetime.datetime(2019, 3, 3, 3, 0, 4)
add a comment |
datetime.datetime.strptime(date_string, format)
The exact syntax should be as above. Changing the order of arguments would work.
datetime.datetime.strptime("Mar 3 03:00:04 2019 GMT","%b %d %H:%M:%S %Y %Z")
datetime.datetime(2019, 3, 3, 3, 0, 4)
datetime.datetime.strptime(date_string, format)
The exact syntax should be as above. Changing the order of arguments would work.
datetime.datetime.strptime("Mar 3 03:00:04 2019 GMT","%b %d %H:%M:%S %Y %Z")
datetime.datetime(2019, 3, 3, 3, 0, 4)
answered Jan 2 at 18:31
RameshRamesh
445
445
add a comment |
add a comment |
You need to flip the args, ie:
import datetime
datetime.datetime.strptime("Mar 3 03:00:04 2019 GMT", "%b %d %H:%M:%S %Y %Z")
add a comment |
You need to flip the args, ie:
import datetime
datetime.datetime.strptime("Mar 3 03:00:04 2019 GMT", "%b %d %H:%M:%S %Y %Z")
add a comment |
You need to flip the args, ie:
import datetime
datetime.datetime.strptime("Mar 3 03:00:04 2019 GMT", "%b %d %H:%M:%S %Y %Z")
You need to flip the args, ie:
import datetime
datetime.datetime.strptime("Mar 3 03:00:04 2019 GMT", "%b %d %H:%M:%S %Y %Z")
answered Jan 2 at 18:24
hchwhchw
34318
34318
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54011240%2fpython-parse-with-strptime-month-day-hoursminuteseconds-year-timezone-does%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
The error is insightful:
ValueError: time data '%b %d %H:%M:%S %Y %Z' does not match format 'Mar 3 03:00:04 2019
– jpp
Jan 2 at 18:26
Related: stackoverflow.com/q/38147923/771848
– alecxe
Jan 2 at 18:49