Accessing timestamp part in data2019 Community Moderator ElectionAccessing the index in 'for' loops?How to access environment variable values?ValueError when using strptime to get a datetime objectHow can I call 'git pull' from within Python?Label encoding across multiple columns in scikit-learnType Error: Image data can not convert to floatImportError: No module named encodings when installing with pip / easy_installImport Error: cannot import name get_importerHow to install pymba Python library for Vimba on Raspberry Pi 3Adding list of numbers to existing csv
Potentiometer like component
It's a yearly task, alright
Why would a jet engine that runs at temps excess of 2000°C burn when it crashes?
"However" used in a conditional clause?
Is a lawful good "antagonist" effective?
Straight line with arrows and dots
What to do when during a meeting client people start to fight (even physically) with each others?
Do I need to leave some extra space available on the disk which my database log files reside, for log backup operations to successfully occur?
Single word request: Harming the benefactor
My story is written in English, but is set in my home country. What language should I use for the dialogue?
What is the blue range indicating on this manifold pressure gauge?
Examples of odd-dimensional manifolds that do not admit contact structure
Should QA ask requirements to developers?
Welcoming 2019 Pi day: How to draw the letter π?
If Invisibility ends because the original caster casts a non-concentration spell, does Invisibility also end on other targets of the original casting?
Plywood subfloor won't screw down in a trailer home
"One can do his homework in the library"
validation vs test vs training accuracy, which one to compare for claiming overfit?
If the Captain's screens are out, does he switch seats with the co-pilot?
What has been your most complicated TikZ drawing?
Replacing Windows 7 security updates with anti-virus?
Silly Sally's Movie
Rejected in 4th interview round citing insufficient years of experience
When two POV characters meet
Accessing timestamp part in data
2019 Community Moderator ElectionAccessing the index in 'for' loops?How to access environment variable values?ValueError when using strptime to get a datetime objectHow can I call 'git pull' from within Python?Label encoding across multiple columns in scikit-learnType Error: Image data can not convert to floatImportError: No module named encodings when installing with pip / easy_installImport Error: cannot import name get_importerHow to install pymba Python library for Vimba on Raspberry Pi 3Adding list of numbers to existing csv
My data format is:
2019-03-07T11:50:03.161033+01:00
My script:
import datetime
print datetime.datetime.strptime('2019-03-07T11:50:03.161033+01:00', '%Y-%m-%dT%H:%M:%S.%f%Z')
I get the error code:
Traceback (most recent call last):
File "test.py", line 2, in <module>
print datetime.datetime.strptime('2019-03-07T11:50:03.161033+01:00', '%Y-%m-%dT%H:%M:%S.%f%Z')
File "/usr/lib/python2.7/_strptime.py", line 332, in _strptime
(data_string, format))
ValueError: time data '2019-03-07T11:50:03.161033+01:00' does not match format '%Y-%m-%dT%H:%M:%S.%f%Z'
How can I access the +01:00 timestamp part?
python
add a comment |
My data format is:
2019-03-07T11:50:03.161033+01:00
My script:
import datetime
print datetime.datetime.strptime('2019-03-07T11:50:03.161033+01:00', '%Y-%m-%dT%H:%M:%S.%f%Z')
I get the error code:
Traceback (most recent call last):
File "test.py", line 2, in <module>
print datetime.datetime.strptime('2019-03-07T11:50:03.161033+01:00', '%Y-%m-%dT%H:%M:%S.%f%Z')
File "/usr/lib/python2.7/_strptime.py", line 332, in _strptime
(data_string, format))
ValueError: time data '2019-03-07T11:50:03.161033+01:00' does not match format '%Y-%m-%dT%H:%M:%S.%f%Z'
How can I access the +01:00 timestamp part?
python
add a comment |
My data format is:
2019-03-07T11:50:03.161033+01:00
My script:
import datetime
print datetime.datetime.strptime('2019-03-07T11:50:03.161033+01:00', '%Y-%m-%dT%H:%M:%S.%f%Z')
I get the error code:
Traceback (most recent call last):
File "test.py", line 2, in <module>
print datetime.datetime.strptime('2019-03-07T11:50:03.161033+01:00', '%Y-%m-%dT%H:%M:%S.%f%Z')
File "/usr/lib/python2.7/_strptime.py", line 332, in _strptime
(data_string, format))
ValueError: time data '2019-03-07T11:50:03.161033+01:00' does not match format '%Y-%m-%dT%H:%M:%S.%f%Z'
How can I access the +01:00 timestamp part?
python
My data format is:
2019-03-07T11:50:03.161033+01:00
My script:
import datetime
print datetime.datetime.strptime('2019-03-07T11:50:03.161033+01:00', '%Y-%m-%dT%H:%M:%S.%f%Z')
I get the error code:
Traceback (most recent call last):
File "test.py", line 2, in <module>
print datetime.datetime.strptime('2019-03-07T11:50:03.161033+01:00', '%Y-%m-%dT%H:%M:%S.%f%Z')
File "/usr/lib/python2.7/_strptime.py", line 332, in _strptime
(data_string, format))
ValueError: time data '2019-03-07T11:50:03.161033+01:00' does not match format '%Y-%m-%dT%H:%M:%S.%f%Z'
How can I access the +01:00 timestamp part?
python
python
asked Mar 7 at 10:56
datacruncherdatacruncher
478
478
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
The issue is in your original data format.
2019-03-07T11:50:03.161033+01:00
The timezone part, +01:00
should actually be +0100
, note the lack of the fullcolon.
If you were to change your original date format to a correct date format, datetime.datetime.strptime
will work.
s = 2019-03-07T11:50:03.161033+0100
datetime.datetime.strptime(s,'%Y-%m-%dT%H:%M:%S.%f%z')
[out] datetime.datetime(2019, 3, 7, 11, 50, 3, 161033, tzinfo=datetime.timezone(datetime.timedelta(0, 3600)))
You could convert your date format as follows:
s = r'2019-03-07T11:50:03.161033+01:00'
lastSemiColor = s.rfind(':') # returns index
s = s[:ii] + s[ii+1:]
print(s) # returns '2019-03-07T11:50:03.161033+0100'
This can be found in the documentation
%z UTC offset in the form ±HHMM[SS[.ffffff]]
add a comment |
Try This,
print('TimeStamp is : %d-%d-%d %d:%d:%d' % (
timeObj.tm_mday, timeObj.tm_mon, timeObj.tm_year, timeObj.tm_hour, timeObj.tm_min, timeObj.tm_sec))
Where is the timeObj import?
– Mitchell van Zuylen
Mar 7 at 11:13
add a comment |
This will work:
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import datetime
if __name__ == '__main__':
a = "2019-03-07T11:50:03.161033+01:00"
b = datetime.datetime.strptime(a, "%Y-%m-%dT%H:%M:%S.%f%z").strftime("%z")
print(b)
Output:
+0100
This doesn't work
– Mitchell van Zuylen
Mar 7 at 11:12
Thank you very much for downgrade. Original answer fixed to be full.
– Dmitrii
Mar 7 at 11:23
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%2f55042125%2faccessing-timestamp-part-in-data%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
The issue is in your original data format.
2019-03-07T11:50:03.161033+01:00
The timezone part, +01:00
should actually be +0100
, note the lack of the fullcolon.
If you were to change your original date format to a correct date format, datetime.datetime.strptime
will work.
s = 2019-03-07T11:50:03.161033+0100
datetime.datetime.strptime(s,'%Y-%m-%dT%H:%M:%S.%f%z')
[out] datetime.datetime(2019, 3, 7, 11, 50, 3, 161033, tzinfo=datetime.timezone(datetime.timedelta(0, 3600)))
You could convert your date format as follows:
s = r'2019-03-07T11:50:03.161033+01:00'
lastSemiColor = s.rfind(':') # returns index
s = s[:ii] + s[ii+1:]
print(s) # returns '2019-03-07T11:50:03.161033+0100'
This can be found in the documentation
%z UTC offset in the form ±HHMM[SS[.ffffff]]
add a comment |
The issue is in your original data format.
2019-03-07T11:50:03.161033+01:00
The timezone part, +01:00
should actually be +0100
, note the lack of the fullcolon.
If you were to change your original date format to a correct date format, datetime.datetime.strptime
will work.
s = 2019-03-07T11:50:03.161033+0100
datetime.datetime.strptime(s,'%Y-%m-%dT%H:%M:%S.%f%z')
[out] datetime.datetime(2019, 3, 7, 11, 50, 3, 161033, tzinfo=datetime.timezone(datetime.timedelta(0, 3600)))
You could convert your date format as follows:
s = r'2019-03-07T11:50:03.161033+01:00'
lastSemiColor = s.rfind(':') # returns index
s = s[:ii] + s[ii+1:]
print(s) # returns '2019-03-07T11:50:03.161033+0100'
This can be found in the documentation
%z UTC offset in the form ±HHMM[SS[.ffffff]]
add a comment |
The issue is in your original data format.
2019-03-07T11:50:03.161033+01:00
The timezone part, +01:00
should actually be +0100
, note the lack of the fullcolon.
If you were to change your original date format to a correct date format, datetime.datetime.strptime
will work.
s = 2019-03-07T11:50:03.161033+0100
datetime.datetime.strptime(s,'%Y-%m-%dT%H:%M:%S.%f%z')
[out] datetime.datetime(2019, 3, 7, 11, 50, 3, 161033, tzinfo=datetime.timezone(datetime.timedelta(0, 3600)))
You could convert your date format as follows:
s = r'2019-03-07T11:50:03.161033+01:00'
lastSemiColor = s.rfind(':') # returns index
s = s[:ii] + s[ii+1:]
print(s) # returns '2019-03-07T11:50:03.161033+0100'
This can be found in the documentation
%z UTC offset in the form ±HHMM[SS[.ffffff]]
The issue is in your original data format.
2019-03-07T11:50:03.161033+01:00
The timezone part, +01:00
should actually be +0100
, note the lack of the fullcolon.
If you were to change your original date format to a correct date format, datetime.datetime.strptime
will work.
s = 2019-03-07T11:50:03.161033+0100
datetime.datetime.strptime(s,'%Y-%m-%dT%H:%M:%S.%f%z')
[out] datetime.datetime(2019, 3, 7, 11, 50, 3, 161033, tzinfo=datetime.timezone(datetime.timedelta(0, 3600)))
You could convert your date format as follows:
s = r'2019-03-07T11:50:03.161033+01:00'
lastSemiColor = s.rfind(':') # returns index
s = s[:ii] + s[ii+1:]
print(s) # returns '2019-03-07T11:50:03.161033+0100'
This can be found in the documentation
%z UTC offset in the form ±HHMM[SS[.ffffff]]
edited Mar 7 at 11:25
Sreeram TP
3,00631438
3,00631438
answered Mar 7 at 11:12
Mitchell van ZuylenMitchell van Zuylen
758421
758421
add a comment |
add a comment |
Try This,
print('TimeStamp is : %d-%d-%d %d:%d:%d' % (
timeObj.tm_mday, timeObj.tm_mon, timeObj.tm_year, timeObj.tm_hour, timeObj.tm_min, timeObj.tm_sec))
Where is the timeObj import?
– Mitchell van Zuylen
Mar 7 at 11:13
add a comment |
Try This,
print('TimeStamp is : %d-%d-%d %d:%d:%d' % (
timeObj.tm_mday, timeObj.tm_mon, timeObj.tm_year, timeObj.tm_hour, timeObj.tm_min, timeObj.tm_sec))
Where is the timeObj import?
– Mitchell van Zuylen
Mar 7 at 11:13
add a comment |
Try This,
print('TimeStamp is : %d-%d-%d %d:%d:%d' % (
timeObj.tm_mday, timeObj.tm_mon, timeObj.tm_year, timeObj.tm_hour, timeObj.tm_min, timeObj.tm_sec))
Try This,
print('TimeStamp is : %d-%d-%d %d:%d:%d' % (
timeObj.tm_mday, timeObj.tm_mon, timeObj.tm_year, timeObj.tm_hour, timeObj.tm_min, timeObj.tm_sec))
answered Mar 7 at 11:07
Aditya DeshpandeAditya Deshpande
917
917
Where is the timeObj import?
– Mitchell van Zuylen
Mar 7 at 11:13
add a comment |
Where is the timeObj import?
– Mitchell van Zuylen
Mar 7 at 11:13
Where is the timeObj import?
– Mitchell van Zuylen
Mar 7 at 11:13
Where is the timeObj import?
– Mitchell van Zuylen
Mar 7 at 11:13
add a comment |
This will work:
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import datetime
if __name__ == '__main__':
a = "2019-03-07T11:50:03.161033+01:00"
b = datetime.datetime.strptime(a, "%Y-%m-%dT%H:%M:%S.%f%z").strftime("%z")
print(b)
Output:
+0100
This doesn't work
– Mitchell van Zuylen
Mar 7 at 11:12
Thank you very much for downgrade. Original answer fixed to be full.
– Dmitrii
Mar 7 at 11:23
add a comment |
This will work:
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import datetime
if __name__ == '__main__':
a = "2019-03-07T11:50:03.161033+01:00"
b = datetime.datetime.strptime(a, "%Y-%m-%dT%H:%M:%S.%f%z").strftime("%z")
print(b)
Output:
+0100
This doesn't work
– Mitchell van Zuylen
Mar 7 at 11:12
Thank you very much for downgrade. Original answer fixed to be full.
– Dmitrii
Mar 7 at 11:23
add a comment |
This will work:
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import datetime
if __name__ == '__main__':
a = "2019-03-07T11:50:03.161033+01:00"
b = datetime.datetime.strptime(a, "%Y-%m-%dT%H:%M:%S.%f%z").strftime("%z")
print(b)
Output:
+0100
This will work:
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import datetime
if __name__ == '__main__':
a = "2019-03-07T11:50:03.161033+01:00"
b = datetime.datetime.strptime(a, "%Y-%m-%dT%H:%M:%S.%f%z").strftime("%z")
print(b)
Output:
+0100
edited Mar 7 at 14:27
kalehmann
2,371521
2,371521
answered Mar 7 at 11:03
DmitriiDmitrii
865
865
This doesn't work
– Mitchell van Zuylen
Mar 7 at 11:12
Thank you very much for downgrade. Original answer fixed to be full.
– Dmitrii
Mar 7 at 11:23
add a comment |
This doesn't work
– Mitchell van Zuylen
Mar 7 at 11:12
Thank you very much for downgrade. Original answer fixed to be full.
– Dmitrii
Mar 7 at 11:23
This doesn't work
– Mitchell van Zuylen
Mar 7 at 11:12
This doesn't work
– Mitchell van Zuylen
Mar 7 at 11:12
Thank you very much for downgrade. Original answer fixed to be full.
– Dmitrii
Mar 7 at 11:23
Thank you very much for downgrade. Original answer fixed to be full.
– Dmitrii
Mar 7 at 11:23
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%2f55042125%2faccessing-timestamp-part-in-data%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