Formatting Datetime.now()JSON.serialize is mucking with my datetime objects. How do I fix this?DateTime.Format() Documentation example causes exceptionTab (t character) Substitute In VisualforceCombine Date from one datetime field with Time from anotherHow to parse Setup Audit Trail's Date formatQuestion on date fields in visualforce pageHelp in converting string to datetime in correct formatWhat's the correct format to set a default value to a DateTime aura:attribute?Need to display the supported locale date formatConvert String into formated dateHow to correctly read CSV file, BLOB not UTF-8 stringDateTime Convertions

Why is "breaking the mould" positively connoted?

Mug and wireframe entirely disappeared

Why is my arithmetic with a long long int behaving this way?

Is there a word for food that's gone 'bad', but is still edible?

Would you use "llamarse" for an animal's name?

What is this weird transparent border appearing inside my Smart Object in Photoshop?

Notation: What does the tilde bellow of the Expectation mean?

Typeset year in old-style numbers with biblatex

Which US defense organization would respond to an invasion like this?

Find magical solution to magical equation

Should homeowners insurance cover the cost of the home?

Latex & Markdown files

It is as simple as ABC

Is Benjen dead?

Adding command shortcuts to /bin

How should I tell my manager I'm not paying for an optional after work event I'm not going to?

How do I, as a DM, handle a party that decides to set up an ambush in a dungeon?

Any examples of liquids volatile at room temp but non-flammable?

getline() vs. fgets(): Control memory allocation

What do "Sech" and "Vich" mean in this sentence?

Will 700 more planes a day fly because of the Heathrow expansion?

Why do people keep telling me that I am a bad photographer?

Can muons decay into quarks?

How does summation index shifting work?



Formatting Datetime.now()


JSON.serialize is mucking with my datetime objects. How do I fix this?DateTime.Format() Documentation example causes exceptionTab (t character) Substitute In VisualforceCombine Date from one datetime field with Time from anotherHow to parse Setup Audit Trail's Date formatQuestion on date fields in visualforce pageHelp in converting string to datetime in correct formatWhat's the correct format to set a default value to a DateTime aura:attribute?Need to display the supported locale date formatConvert String into formated dateHow to correctly read CSV file, BLOB not UTF-8 stringDateTime Convertions






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








1















I need to format my Datetime.now() to be accepted for a SOAP request.



I can't seem to find a way to format it online. Can anyone advise? I need it to look like: 2019-05-02T21:20:29.999Z



Currently I have tried: .format(), .formatLong(),
Datetime.now().format('yyyy-MM-dd'T'HH:mm:ss.SSSZ') which I believe is the correct way, but this displays like so: 2019-05-03T16:45:18.646-0400.










share|improve this question




























    1















    I need to format my Datetime.now() to be accepted for a SOAP request.



    I can't seem to find a way to format it online. Can anyone advise? I need it to look like: 2019-05-02T21:20:29.999Z



    Currently I have tried: .format(), .formatLong(),
    Datetime.now().format('yyyy-MM-dd'T'HH:mm:ss.SSSZ') which I believe is the correct way, but this displays like so: 2019-05-03T16:45:18.646-0400.










    share|improve this question
























      1












      1








      1








      I need to format my Datetime.now() to be accepted for a SOAP request.



      I can't seem to find a way to format it online. Can anyone advise? I need it to look like: 2019-05-02T21:20:29.999Z



      Currently I have tried: .format(), .formatLong(),
      Datetime.now().format('yyyy-MM-dd'T'HH:mm:ss.SSSZ') which I believe is the correct way, but this displays like so: 2019-05-03T16:45:18.646-0400.










      share|improve this question














      I need to format my Datetime.now() to be accepted for a SOAP request.



      I can't seem to find a way to format it online. Can anyone advise? I need it to look like: 2019-05-02T21:20:29.999Z



      Currently I have tried: .format(), .formatLong(),
      Datetime.now().format('yyyy-MM-dd'T'HH:mm:ss.SSSZ') which I believe is the correct way, but this displays like so: 2019-05-03T16:45:18.646-0400.







      apex datetime formatting






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 2 hours ago









      OliviaOlivia

      1,417427




      1,417427




















          2 Answers
          2






          active

          oldest

          votes


















          3














          You are on the right track that you need to pass in a specific format string to Datetime.now().format(...). Notice how you escape the T in your current format:



          Datetime.now().format('yyyy-MM-dd'T'HH:mm:ss.SSSZ')


          Just do the same thing with the Z:



          Datetime.now().format('yyyy-MM-dd'T'HH:mm:ss.SSS'Z'')


          Note that Z is a valid argument in SimpleDateFormat:




          Letter Date or Time Component Presentation Examples 
          ... ... ... ...
          Z Time zone RFC 822 time zone -0800



          See also:



          • DateTime.Format() Documentation example causes exception

          • JSON.serialize is mucking with my datetime objects. How do I fix this?

          • Salesforce Apex: ISO Timestamp Format Function





          share|improve this answer

























          • ah I forgot to escape the Z. Thank you, you're the best!

            – Olivia
            2 hours ago


















          1














          Another approach



          String s = JSON.serialize(Datetime.now()).replace('"','');


          or



          String s = JSON.serialize(Datetime.now()).substringBetween('"');





          share|improve this answer























            Your Answer








            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "459"
            ;
            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: false,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            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%2fsalesforce.stackexchange.com%2fquestions%2f261098%2fformatting-datetime-now%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









            3














            You are on the right track that you need to pass in a specific format string to Datetime.now().format(...). Notice how you escape the T in your current format:



            Datetime.now().format('yyyy-MM-dd'T'HH:mm:ss.SSSZ')


            Just do the same thing with the Z:



            Datetime.now().format('yyyy-MM-dd'T'HH:mm:ss.SSS'Z'')


            Note that Z is a valid argument in SimpleDateFormat:




            Letter Date or Time Component Presentation Examples 
            ... ... ... ...
            Z Time zone RFC 822 time zone -0800



            See also:



            • DateTime.Format() Documentation example causes exception

            • JSON.serialize is mucking with my datetime objects. How do I fix this?

            • Salesforce Apex: ISO Timestamp Format Function





            share|improve this answer

























            • ah I forgot to escape the Z. Thank you, you're the best!

              – Olivia
              2 hours ago















            3














            You are on the right track that you need to pass in a specific format string to Datetime.now().format(...). Notice how you escape the T in your current format:



            Datetime.now().format('yyyy-MM-dd'T'HH:mm:ss.SSSZ')


            Just do the same thing with the Z:



            Datetime.now().format('yyyy-MM-dd'T'HH:mm:ss.SSS'Z'')


            Note that Z is a valid argument in SimpleDateFormat:




            Letter Date or Time Component Presentation Examples 
            ... ... ... ...
            Z Time zone RFC 822 time zone -0800



            See also:



            • DateTime.Format() Documentation example causes exception

            • JSON.serialize is mucking with my datetime objects. How do I fix this?

            • Salesforce Apex: ISO Timestamp Format Function





            share|improve this answer

























            • ah I forgot to escape the Z. Thank you, you're the best!

              – Olivia
              2 hours ago













            3












            3








            3







            You are on the right track that you need to pass in a specific format string to Datetime.now().format(...). Notice how you escape the T in your current format:



            Datetime.now().format('yyyy-MM-dd'T'HH:mm:ss.SSSZ')


            Just do the same thing with the Z:



            Datetime.now().format('yyyy-MM-dd'T'HH:mm:ss.SSS'Z'')


            Note that Z is a valid argument in SimpleDateFormat:




            Letter Date or Time Component Presentation Examples 
            ... ... ... ...
            Z Time zone RFC 822 time zone -0800



            See also:



            • DateTime.Format() Documentation example causes exception

            • JSON.serialize is mucking with my datetime objects. How do I fix this?

            • Salesforce Apex: ISO Timestamp Format Function





            share|improve this answer















            You are on the right track that you need to pass in a specific format string to Datetime.now().format(...). Notice how you escape the T in your current format:



            Datetime.now().format('yyyy-MM-dd'T'HH:mm:ss.SSSZ')


            Just do the same thing with the Z:



            Datetime.now().format('yyyy-MM-dd'T'HH:mm:ss.SSS'Z'')


            Note that Z is a valid argument in SimpleDateFormat:




            Letter Date or Time Component Presentation Examples 
            ... ... ... ...
            Z Time zone RFC 822 time zone -0800



            See also:



            • DateTime.Format() Documentation example causes exception

            • JSON.serialize is mucking with my datetime objects. How do I fix this?

            • Salesforce Apex: ISO Timestamp Format Function






            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited 20 mins ago









            David Cheng

            2,61452047




            2,61452047










            answered 2 hours ago









            Adrian LarsonAdrian Larson

            111k19123262




            111k19123262












            • ah I forgot to escape the Z. Thank you, you're the best!

              – Olivia
              2 hours ago

















            • ah I forgot to escape the Z. Thank you, you're the best!

              – Olivia
              2 hours ago
















            ah I forgot to escape the Z. Thank you, you're the best!

            – Olivia
            2 hours ago





            ah I forgot to escape the Z. Thank you, you're the best!

            – Olivia
            2 hours ago













            1














            Another approach



            String s = JSON.serialize(Datetime.now()).replace('"','');


            or



            String s = JSON.serialize(Datetime.now()).substringBetween('"');





            share|improve this answer



























              1














              Another approach



              String s = JSON.serialize(Datetime.now()).replace('"','');


              or



              String s = JSON.serialize(Datetime.now()).substringBetween('"');





              share|improve this answer

























                1












                1








                1







                Another approach



                String s = JSON.serialize(Datetime.now()).replace('"','');


                or



                String s = JSON.serialize(Datetime.now()).substringBetween('"');





                share|improve this answer













                Another approach



                String s = JSON.serialize(Datetime.now()).replace('"','');


                or



                String s = JSON.serialize(Datetime.now()).substringBetween('"');






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered 1 hour ago









                cropredycropredy

                36.7k444126




                36.7k444126



























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Salesforce Stack Exchange!


                    • 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%2fsalesforce.stackexchange.com%2fquestions%2f261098%2fformatting-datetime-now%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

                    Canceling a color specificationRandomly assigning color to Graphics3D objects?Default color for Filling in Mathematica 9Coloring specific elements of sets with a prime modified order in an array plotHow to pick a color differing significantly from the colors already in a given color list?Detection of the text colorColor numbers based on their valueCan color schemes for use with ColorData include opacity specification?My dynamic color schemes

                    Invision Community Contents History See also References External links Navigation menuProprietaryinvisioncommunity.comIPS Community ForumsIPS Community Forumsthis blog entry"License Changes, IP.Board 3.4, and the Future""Interview -- Matt Mecham of Ibforums""CEO Invision Power Board, Matt Mecham Is a Liar, Thief!"IPB License Explanation 1.3, 1.3.1, 2.0, and 2.1ArchivedSecurity Fixes, Updates And Enhancements For IPB 1.3.1Archived"New Demo Accounts - Invision Power Services"the original"New Default Skin"the original"Invision Power Board 3.0.0 and Applications Released"the original"Archived copy"the original"Perpetual licenses being done away with""Release Notes - Invision Power Services""Introducing: IPS Community Suite 4!"Invision Community Release Notes

                    François Viète Contents Biography Work and thought Bibliography See also Notes Further reading External links Navigation menup. 21Google Bookspp. 75–77Google BooksDe thou (from University of Saint Andrews)ArchivedGoogle BooksGoogle BooksGoogle BooksGoogle booksGoogle Bookscc-parthenay.frL'histoire universelle (fr)Universal History (en)ArchivedAdsabs.harvard.eduPagesperso-orange.frArchive.orgChikara Sasaki. Descartes' mathematical thought p.259Google BooksGoogle BooksGoogle Bookspp. 152 and onwardGoogle BooksGoogle BooksScribd.comGoogle Books1257-7979Google BooksGoogle BooksGoogle BooksGoogle BooksGoogle BooksGoogle BooksGallica.bnf.frGoogle BooksGoogle Books"François Viète"Francois Viète: Father of Modern Algebraic NotationThe Lawyer and the GamblerAbout TarporleySite de Jean-Paul GuichardL'algèbre nouvelle"About the Harmonicon"cb120511976(data)1188044800000 0001 0913 5903n82164680ola2013766880073431702w6vt1sb70287374827140948071409480