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










2















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?










share|improve this question


























    2















    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?










    share|improve this question
























      2












      2








      2








      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?










      share|improve this question














      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






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 7 at 10:56









      datacruncherdatacruncher

      478




      478






















          3 Answers
          3






          active

          oldest

          votes


















          1














          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]] 





          share|improve this answer
































            0














            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))





            share|improve this answer























            • Where is the timeObj import?

              – Mitchell van Zuylen
              Mar 7 at 11:13


















            0














            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







            share|improve this answer

























            • 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










            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
            );



            );













            draft saved

            draft discarded


















            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









            1














            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]] 





            share|improve this answer





























              1














              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]] 





              share|improve this answer



























                1












                1








                1







                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]] 





                share|improve this answer















                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]] 






                share|improve this answer














                share|improve this answer



                share|improve this answer








                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























                    0














                    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))





                    share|improve this answer























                    • Where is the timeObj import?

                      – Mitchell van Zuylen
                      Mar 7 at 11:13















                    0














                    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))





                    share|improve this answer























                    • Where is the timeObj import?

                      – Mitchell van Zuylen
                      Mar 7 at 11:13













                    0












                    0








                    0







                    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))





                    share|improve this answer













                    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))






                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Mar 7 at 11:07









                    Aditya DeshpandeAditya Deshpande

                    917




                    917












                    • 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





                    Where is the timeObj import?

                    – Mitchell van Zuylen
                    Mar 7 at 11:13











                    0














                    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







                    share|improve this answer

























                    • 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















                    0














                    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







                    share|improve this answer

























                    • 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













                    0












                    0








                    0







                    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







                    share|improve this answer















                    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








                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    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

















                    • 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

















                    draft saved

                    draft discarded
















































                    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.




                    draft saved


                    draft discarded














                    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





















































                    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







                    Popular posts from this blog

                    Identity Server 4 is not redirecting to Angular app after login2019 Community Moderator ElectionIdentity Server 4 and dockerIdentityserver implicit flow unauthorized_clientIdentityServer Hybrid Flow - Access Token is null after user successful loginIdentity Server to MVC client : Page Redirect After loginLogin with Steam OpenId(oidc-client-js)Identity Server 4+.NET Core 2.0 + IdentityIdentityServer4 post-login redirect not working in Edge browserCall to IdentityServer4 generates System.NullReferenceException: Object reference not set to an instance of an objectIdentityServer4 without HTTPS not workingHow to get Authorization code from identity server without login form

                    2005 Ahvaz unrest Contents Background Causes Casualties Aftermath See also References Navigation menue"At Least 10 Are Killed by Bombs in Iran""Iran"Archived"Arab-Iranians in Iran to make April 15 'Day of Fury'"State of Mind, State of Order: Reactions to Ethnic Unrest in the Islamic Republic of Iran.10.1111/j.1754-9469.2008.00028.x"Iran hangs Arab separatists"Iran Overview from ArchivedConstitution of the Islamic Republic of Iran"Tehran puzzled by forged 'riots' letter""Iran and its minorities: Down in the second class""Iran: Handling Of Ahvaz Unrest Could End With Televised Confessions""Bombings Rock Iran Ahead of Election""Five die in Iran ethnic clashes""Iran: Need for restraint as anniversary of unrest in Khuzestan approaches"Archived"Iranian Sunni protesters killed in clashes with security forces"Archived

                    Can't initialize raids on a new ASUS Prime B360M-A motherboard2019 Community Moderator ElectionSimilar to RAID config yet more like mirroring solution?Can't get motherboard serial numberWhy does the BIOS entry point start with a WBINVD instruction?UEFI performance Asus Maximus V Extreme