How to format LocalDate to string?












82















I have a LocalDate variable called date,when I print it displays 1988-05-05 I need to convert this to be printed as 05.May 1988.How to do this?










share|improve this question


















  • 3





    Take a look at the DateTimeFormatter class. It even has examples of how to convert to and from Strings.

    – azurefrog
    Jan 27 '15 at 18:24






  • 2





    You should show some code, what you have tried so far and what's not working so people can help you.

    – bvidal
    Jan 27 '15 at 18:24











  • I tried to do that but because of this annoying "it does not meet our quality standards" thing I finally gave up,it took me 15 minutes just to post this because i had to correct "i" with "I".

    – Jasko
    Jan 27 '15 at 18:29
















82















I have a LocalDate variable called date,when I print it displays 1988-05-05 I need to convert this to be printed as 05.May 1988.How to do this?










share|improve this question


















  • 3





    Take a look at the DateTimeFormatter class. It even has examples of how to convert to and from Strings.

    – azurefrog
    Jan 27 '15 at 18:24






  • 2





    You should show some code, what you have tried so far and what's not working so people can help you.

    – bvidal
    Jan 27 '15 at 18:24











  • I tried to do that but because of this annoying "it does not meet our quality standards" thing I finally gave up,it took me 15 minutes just to post this because i had to correct "i" with "I".

    – Jasko
    Jan 27 '15 at 18:29














82












82








82


6






I have a LocalDate variable called date,when I print it displays 1988-05-05 I need to convert this to be printed as 05.May 1988.How to do this?










share|improve this question














I have a LocalDate variable called date,when I print it displays 1988-05-05 I need to convert this to be printed as 05.May 1988.How to do this?







java






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Jan 27 '15 at 18:21









JaskoJasko

565147




565147








  • 3





    Take a look at the DateTimeFormatter class. It even has examples of how to convert to and from Strings.

    – azurefrog
    Jan 27 '15 at 18:24






  • 2





    You should show some code, what you have tried so far and what's not working so people can help you.

    – bvidal
    Jan 27 '15 at 18:24











  • I tried to do that but because of this annoying "it does not meet our quality standards" thing I finally gave up,it took me 15 minutes just to post this because i had to correct "i" with "I".

    – Jasko
    Jan 27 '15 at 18:29














  • 3





    Take a look at the DateTimeFormatter class. It even has examples of how to convert to and from Strings.

    – azurefrog
    Jan 27 '15 at 18:24






  • 2





    You should show some code, what you have tried so far and what's not working so people can help you.

    – bvidal
    Jan 27 '15 at 18:24











  • I tried to do that but because of this annoying "it does not meet our quality standards" thing I finally gave up,it took me 15 minutes just to post this because i had to correct "i" with "I".

    – Jasko
    Jan 27 '15 at 18:29








3




3





Take a look at the DateTimeFormatter class. It even has examples of how to convert to and from Strings.

– azurefrog
Jan 27 '15 at 18:24





Take a look at the DateTimeFormatter class. It even has examples of how to convert to and from Strings.

– azurefrog
Jan 27 '15 at 18:24




2




2





You should show some code, what you have tried so far and what's not working so people can help you.

– bvidal
Jan 27 '15 at 18:24





You should show some code, what you have tried so far and what's not working so people can help you.

– bvidal
Jan 27 '15 at 18:24













I tried to do that but because of this annoying "it does not meet our quality standards" thing I finally gave up,it took me 15 minutes just to post this because i had to correct "i" with "I".

– Jasko
Jan 27 '15 at 18:29





I tried to do that but because of this annoying "it does not meet our quality standards" thing I finally gave up,it took me 15 minutes just to post this because i had to correct "i" with "I".

– Jasko
Jan 27 '15 at 18:29












7 Answers
7






active

oldest

votes


















187














SimpleDateFormat will not work if he is starting with LocalDate which is new in Java 8. From what I can see, you will have to use DateTimeFormatter, http://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html.



LocalDate localDate = LocalDate.now();//For reference
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd LLLL yyyy");
String formattedString = localDate.format(formatter);


That should print 05 May 1988. To get the period after the day and before the month, you might have to use "dd'.LLLL yyyy"






share|improve this answer





















  • 3





    Thank you very much,this helps,but it didn't work with 'LLLL' to show name of the month but with 'MMMM' i found this strange since even in the documentation it says otherwise.But once again thank you for helping me.

    – Jasko
    Jan 27 '15 at 19:17






  • 1





    Now localDate.format(formatter); doesn't work at all

    – Tot
    Dec 10 '16 at 3:12











  • which version JDK your Using @ProgrammersBlock

    – Lova Chittumuri
    Jan 31 '18 at 11:44



















7














Could be short as:



LocalDate.now().format(
DateTimeFormatter.ofPattern("dd/MM/yyyy"));





share|improve this answer

































    3














    System.out.println(LocalDate.now().format(DateTimeFormatter.ofPattern("dd.MMMM yyyy")));



    The above answer shows it for today






    share|improve this answer

































      1














      With the help of ProgrammersBlock posts I came up with this. My needs were slightly different. I needed to take a string and return it as a LocalDate object. I was handed code that was using the older Calendar and SimpleDateFormat. I wanted to make it a little more current. This is what I came up with.



          import java.time.LocalDate;
      import java.time.format.DateTimeFormatter;


      void ExampleFormatDate() {

      LocalDate formattedDate = null; //Declare LocalDate variable to receive the formatted date.
      DateTimeFormatter dateTimeFormatter; //Declare date formatter
      String rawDate = "2000-01-01"; //Test string that holds a date to format and parse.

      dateTimeFormatter = DateTimeFormatter.ISO_LOCAL_DATE;

      //formattedDate.parse(String string) wraps the String.format(String string, DateTimeFormatter format) method.
      //First, the rawDate string is formatted according to DateTimeFormatter. Second, that formatted string is parsed into
      //the LocalDate formattedDate object.
      formattedDate = formattedDate.parse(String.format(rawDate, dateTimeFormatter));

      }


      Hopefully this will help someone, if anyone sees a better way of doing this task please add your input.






      share|improve this answer































        0















        LocalDate.now().format(DateTimeFormatter.ofPattern("dd/MM/yyyy").toString())




        Ex. You can use any kind of date pattern
        1. dd/MM/yyyy
        2. dd/MM/yy
        3. yyyy/MM/dd






        share|improve this answer































          -5














          LocalDate date = LocalDate.now();//For reference
          System.out.println(DateTimeFormat.longDate().print(date));
          System.out.println(date.toString("dd.MMMM YYYY"));


          Beware, language of month depends of locale or something.



          see more






          share|improve this answer

































            -9














            A pretty nice way to do this is to use SimpleDateFormat I'll show you how:



            SimpleDateFormat sdf = new SimpleDateFormat("d MMMM YYYY");
            Date d = new Date();
            sdf.format(d);


            I see that you have the date in a variable:



            sdf.format(variable_name);


            Cheers.






            share|improve this answer



















            • 1





              SimpleDateFormat can work with LocalDate?

              – Tom
              Jan 27 '15 at 18:30











            • What do you mean by 'can work with'?

              – nom
              Jan 27 '15 at 18:32






            • 2





              OP wants to print the content of a LocalDate instance in a specific format. How could SimpleDateFormat help him here?

              – Tom
              Jan 27 '15 at 18:34











            • From what I know, LocalDate is already formatted....

              – nom
              Jan 27 '15 at 18:38











            • @jasko: Use: Date dt = sdf.format(varName);

              – nom
              Jan 27 '15 at 18:40











            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%2f28177370%2fhow-to-format-localdate-to-string%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            7 Answers
            7






            active

            oldest

            votes








            7 Answers
            7






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            187














            SimpleDateFormat will not work if he is starting with LocalDate which is new in Java 8. From what I can see, you will have to use DateTimeFormatter, http://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html.



            LocalDate localDate = LocalDate.now();//For reference
            DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd LLLL yyyy");
            String formattedString = localDate.format(formatter);


            That should print 05 May 1988. To get the period after the day and before the month, you might have to use "dd'.LLLL yyyy"






            share|improve this answer





















            • 3





              Thank you very much,this helps,but it didn't work with 'LLLL' to show name of the month but with 'MMMM' i found this strange since even in the documentation it says otherwise.But once again thank you for helping me.

              – Jasko
              Jan 27 '15 at 19:17






            • 1





              Now localDate.format(formatter); doesn't work at all

              – Tot
              Dec 10 '16 at 3:12











            • which version JDK your Using @ProgrammersBlock

              – Lova Chittumuri
              Jan 31 '18 at 11:44
















            187














            SimpleDateFormat will not work if he is starting with LocalDate which is new in Java 8. From what I can see, you will have to use DateTimeFormatter, http://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html.



            LocalDate localDate = LocalDate.now();//For reference
            DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd LLLL yyyy");
            String formattedString = localDate.format(formatter);


            That should print 05 May 1988. To get the period after the day and before the month, you might have to use "dd'.LLLL yyyy"






            share|improve this answer





















            • 3





              Thank you very much,this helps,but it didn't work with 'LLLL' to show name of the month but with 'MMMM' i found this strange since even in the documentation it says otherwise.But once again thank you for helping me.

              – Jasko
              Jan 27 '15 at 19:17






            • 1





              Now localDate.format(formatter); doesn't work at all

              – Tot
              Dec 10 '16 at 3:12











            • which version JDK your Using @ProgrammersBlock

              – Lova Chittumuri
              Jan 31 '18 at 11:44














            187












            187








            187







            SimpleDateFormat will not work if he is starting with LocalDate which is new in Java 8. From what I can see, you will have to use DateTimeFormatter, http://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html.



            LocalDate localDate = LocalDate.now();//For reference
            DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd LLLL yyyy");
            String formattedString = localDate.format(formatter);


            That should print 05 May 1988. To get the period after the day and before the month, you might have to use "dd'.LLLL yyyy"






            share|improve this answer















            SimpleDateFormat will not work if he is starting with LocalDate which is new in Java 8. From what I can see, you will have to use DateTimeFormatter, http://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html.



            LocalDate localDate = LocalDate.now();//For reference
            DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd LLLL yyyy");
            String formattedString = localDate.format(formatter);


            That should print 05 May 1988. To get the period after the day and before the month, you might have to use "dd'.LLLL yyyy"







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Jan 27 '15 at 19:09

























            answered Jan 27 '15 at 19:03









            ProgrammersBlockProgrammersBlock

            2,96131316




            2,96131316








            • 3





              Thank you very much,this helps,but it didn't work with 'LLLL' to show name of the month but with 'MMMM' i found this strange since even in the documentation it says otherwise.But once again thank you for helping me.

              – Jasko
              Jan 27 '15 at 19:17






            • 1





              Now localDate.format(formatter); doesn't work at all

              – Tot
              Dec 10 '16 at 3:12











            • which version JDK your Using @ProgrammersBlock

              – Lova Chittumuri
              Jan 31 '18 at 11:44














            • 3





              Thank you very much,this helps,but it didn't work with 'LLLL' to show name of the month but with 'MMMM' i found this strange since even in the documentation it says otherwise.But once again thank you for helping me.

              – Jasko
              Jan 27 '15 at 19:17






            • 1





              Now localDate.format(formatter); doesn't work at all

              – Tot
              Dec 10 '16 at 3:12











            • which version JDK your Using @ProgrammersBlock

              – Lova Chittumuri
              Jan 31 '18 at 11:44








            3




            3





            Thank you very much,this helps,but it didn't work with 'LLLL' to show name of the month but with 'MMMM' i found this strange since even in the documentation it says otherwise.But once again thank you for helping me.

            – Jasko
            Jan 27 '15 at 19:17





            Thank you very much,this helps,but it didn't work with 'LLLL' to show name of the month but with 'MMMM' i found this strange since even in the documentation it says otherwise.But once again thank you for helping me.

            – Jasko
            Jan 27 '15 at 19:17




            1




            1





            Now localDate.format(formatter); doesn't work at all

            – Tot
            Dec 10 '16 at 3:12





            Now localDate.format(formatter); doesn't work at all

            – Tot
            Dec 10 '16 at 3:12













            which version JDK your Using @ProgrammersBlock

            – Lova Chittumuri
            Jan 31 '18 at 11:44





            which version JDK your Using @ProgrammersBlock

            – Lova Chittumuri
            Jan 31 '18 at 11:44













            7














            Could be short as:



            LocalDate.now().format(
            DateTimeFormatter.ofPattern("dd/MM/yyyy"));





            share|improve this answer






























              7














              Could be short as:



              LocalDate.now().format(
              DateTimeFormatter.ofPattern("dd/MM/yyyy"));





              share|improve this answer




























                7












                7








                7







                Could be short as:



                LocalDate.now().format(
                DateTimeFormatter.ofPattern("dd/MM/yyyy"));





                share|improve this answer















                Could be short as:



                LocalDate.now().format(
                DateTimeFormatter.ofPattern("dd/MM/yyyy"));






                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Nov 15 '18 at 14:12

























                answered Sep 23 '18 at 14:38









                ZonZon

                5,33544153




                5,33544153























                    3














                    System.out.println(LocalDate.now().format(DateTimeFormatter.ofPattern("dd.MMMM yyyy")));



                    The above answer shows it for today






                    share|improve this answer






























                      3














                      System.out.println(LocalDate.now().format(DateTimeFormatter.ofPattern("dd.MMMM yyyy")));



                      The above answer shows it for today






                      share|improve this answer




























                        3












                        3








                        3







                        System.out.println(LocalDate.now().format(DateTimeFormatter.ofPattern("dd.MMMM yyyy")));



                        The above answer shows it for today






                        share|improve this answer















                        System.out.println(LocalDate.now().format(DateTimeFormatter.ofPattern("dd.MMMM yyyy")));



                        The above answer shows it for today







                        share|improve this answer














                        share|improve this answer



                        share|improve this answer








                        edited Aug 8 '18 at 18:54

























                        answered Aug 8 '18 at 18:41









                        karthik rkarthik r

                        19735




                        19735























                            1














                            With the help of ProgrammersBlock posts I came up with this. My needs were slightly different. I needed to take a string and return it as a LocalDate object. I was handed code that was using the older Calendar and SimpleDateFormat. I wanted to make it a little more current. This is what I came up with.



                                import java.time.LocalDate;
                            import java.time.format.DateTimeFormatter;


                            void ExampleFormatDate() {

                            LocalDate formattedDate = null; //Declare LocalDate variable to receive the formatted date.
                            DateTimeFormatter dateTimeFormatter; //Declare date formatter
                            String rawDate = "2000-01-01"; //Test string that holds a date to format and parse.

                            dateTimeFormatter = DateTimeFormatter.ISO_LOCAL_DATE;

                            //formattedDate.parse(String string) wraps the String.format(String string, DateTimeFormatter format) method.
                            //First, the rawDate string is formatted according to DateTimeFormatter. Second, that formatted string is parsed into
                            //the LocalDate formattedDate object.
                            formattedDate = formattedDate.parse(String.format(rawDate, dateTimeFormatter));

                            }


                            Hopefully this will help someone, if anyone sees a better way of doing this task please add your input.






                            share|improve this answer




























                              1














                              With the help of ProgrammersBlock posts I came up with this. My needs were slightly different. I needed to take a string and return it as a LocalDate object. I was handed code that was using the older Calendar and SimpleDateFormat. I wanted to make it a little more current. This is what I came up with.



                                  import java.time.LocalDate;
                              import java.time.format.DateTimeFormatter;


                              void ExampleFormatDate() {

                              LocalDate formattedDate = null; //Declare LocalDate variable to receive the formatted date.
                              DateTimeFormatter dateTimeFormatter; //Declare date formatter
                              String rawDate = "2000-01-01"; //Test string that holds a date to format and parse.

                              dateTimeFormatter = DateTimeFormatter.ISO_LOCAL_DATE;

                              //formattedDate.parse(String string) wraps the String.format(String string, DateTimeFormatter format) method.
                              //First, the rawDate string is formatted according to DateTimeFormatter. Second, that formatted string is parsed into
                              //the LocalDate formattedDate object.
                              formattedDate = formattedDate.parse(String.format(rawDate, dateTimeFormatter));

                              }


                              Hopefully this will help someone, if anyone sees a better way of doing this task please add your input.






                              share|improve this answer


























                                1












                                1








                                1







                                With the help of ProgrammersBlock posts I came up with this. My needs were slightly different. I needed to take a string and return it as a LocalDate object. I was handed code that was using the older Calendar and SimpleDateFormat. I wanted to make it a little more current. This is what I came up with.



                                    import java.time.LocalDate;
                                import java.time.format.DateTimeFormatter;


                                void ExampleFormatDate() {

                                LocalDate formattedDate = null; //Declare LocalDate variable to receive the formatted date.
                                DateTimeFormatter dateTimeFormatter; //Declare date formatter
                                String rawDate = "2000-01-01"; //Test string that holds a date to format and parse.

                                dateTimeFormatter = DateTimeFormatter.ISO_LOCAL_DATE;

                                //formattedDate.parse(String string) wraps the String.format(String string, DateTimeFormatter format) method.
                                //First, the rawDate string is formatted according to DateTimeFormatter. Second, that formatted string is parsed into
                                //the LocalDate formattedDate object.
                                formattedDate = formattedDate.parse(String.format(rawDate, dateTimeFormatter));

                                }


                                Hopefully this will help someone, if anyone sees a better way of doing this task please add your input.






                                share|improve this answer













                                With the help of ProgrammersBlock posts I came up with this. My needs were slightly different. I needed to take a string and return it as a LocalDate object. I was handed code that was using the older Calendar and SimpleDateFormat. I wanted to make it a little more current. This is what I came up with.



                                    import java.time.LocalDate;
                                import java.time.format.DateTimeFormatter;


                                void ExampleFormatDate() {

                                LocalDate formattedDate = null; //Declare LocalDate variable to receive the formatted date.
                                DateTimeFormatter dateTimeFormatter; //Declare date formatter
                                String rawDate = "2000-01-01"; //Test string that holds a date to format and parse.

                                dateTimeFormatter = DateTimeFormatter.ISO_LOCAL_DATE;

                                //formattedDate.parse(String string) wraps the String.format(String string, DateTimeFormatter format) method.
                                //First, the rawDate string is formatted according to DateTimeFormatter. Second, that formatted string is parsed into
                                //the LocalDate formattedDate object.
                                formattedDate = formattedDate.parse(String.format(rawDate, dateTimeFormatter));

                                }


                                Hopefully this will help someone, if anyone sees a better way of doing this task please add your input.







                                share|improve this answer












                                share|improve this answer



                                share|improve this answer










                                answered Feb 25 '18 at 18:40









                                PkinPkin

                                112




                                112























                                    0















                                    LocalDate.now().format(DateTimeFormatter.ofPattern("dd/MM/yyyy").toString())




                                    Ex. You can use any kind of date pattern
                                    1. dd/MM/yyyy
                                    2. dd/MM/yy
                                    3. yyyy/MM/dd






                                    share|improve this answer




























                                      0















                                      LocalDate.now().format(DateTimeFormatter.ofPattern("dd/MM/yyyy").toString())




                                      Ex. You can use any kind of date pattern
                                      1. dd/MM/yyyy
                                      2. dd/MM/yy
                                      3. yyyy/MM/dd






                                      share|improve this answer


























                                        0












                                        0








                                        0








                                        LocalDate.now().format(DateTimeFormatter.ofPattern("dd/MM/yyyy").toString())




                                        Ex. You can use any kind of date pattern
                                        1. dd/MM/yyyy
                                        2. dd/MM/yy
                                        3. yyyy/MM/dd






                                        share|improve this answer














                                        LocalDate.now().format(DateTimeFormatter.ofPattern("dd/MM/yyyy").toString())




                                        Ex. You can use any kind of date pattern
                                        1. dd/MM/yyyy
                                        2. dd/MM/yy
                                        3. yyyy/MM/dd







                                        share|improve this answer












                                        share|improve this answer



                                        share|improve this answer










                                        answered Dec 13 '18 at 7:27









                                        Pavan TPavan T

                                        329310




                                        329310























                                            -5














                                            LocalDate date = LocalDate.now();//For reference
                                            System.out.println(DateTimeFormat.longDate().print(date));
                                            System.out.println(date.toString("dd.MMMM YYYY"));


                                            Beware, language of month depends of locale or something.



                                            see more






                                            share|improve this answer






























                                              -5














                                              LocalDate date = LocalDate.now();//For reference
                                              System.out.println(DateTimeFormat.longDate().print(date));
                                              System.out.println(date.toString("dd.MMMM YYYY"));


                                              Beware, language of month depends of locale or something.



                                              see more






                                              share|improve this answer




























                                                -5












                                                -5








                                                -5







                                                LocalDate date = LocalDate.now();//For reference
                                                System.out.println(DateTimeFormat.longDate().print(date));
                                                System.out.println(date.toString("dd.MMMM YYYY"));


                                                Beware, language of month depends of locale or something.



                                                see more






                                                share|improve this answer















                                                LocalDate date = LocalDate.now();//For reference
                                                System.out.println(DateTimeFormat.longDate().print(date));
                                                System.out.println(date.toString("dd.MMMM YYYY"));


                                                Beware, language of month depends of locale or something.



                                                see more







                                                share|improve this answer














                                                share|improve this answer



                                                share|improve this answer








                                                edited Jan 26 '17 at 15:51

























                                                answered Jan 20 '17 at 13:52









                                                SVK PETOSVK PETO

                                                14




                                                14























                                                    -9














                                                    A pretty nice way to do this is to use SimpleDateFormat I'll show you how:



                                                    SimpleDateFormat sdf = new SimpleDateFormat("d MMMM YYYY");
                                                    Date d = new Date();
                                                    sdf.format(d);


                                                    I see that you have the date in a variable:



                                                    sdf.format(variable_name);


                                                    Cheers.






                                                    share|improve this answer



















                                                    • 1





                                                      SimpleDateFormat can work with LocalDate?

                                                      – Tom
                                                      Jan 27 '15 at 18:30











                                                    • What do you mean by 'can work with'?

                                                      – nom
                                                      Jan 27 '15 at 18:32






                                                    • 2





                                                      OP wants to print the content of a LocalDate instance in a specific format. How could SimpleDateFormat help him here?

                                                      – Tom
                                                      Jan 27 '15 at 18:34











                                                    • From what I know, LocalDate is already formatted....

                                                      – nom
                                                      Jan 27 '15 at 18:38











                                                    • @jasko: Use: Date dt = sdf.format(varName);

                                                      – nom
                                                      Jan 27 '15 at 18:40
















                                                    -9














                                                    A pretty nice way to do this is to use SimpleDateFormat I'll show you how:



                                                    SimpleDateFormat sdf = new SimpleDateFormat("d MMMM YYYY");
                                                    Date d = new Date();
                                                    sdf.format(d);


                                                    I see that you have the date in a variable:



                                                    sdf.format(variable_name);


                                                    Cheers.






                                                    share|improve this answer



















                                                    • 1





                                                      SimpleDateFormat can work with LocalDate?

                                                      – Tom
                                                      Jan 27 '15 at 18:30











                                                    • What do you mean by 'can work with'?

                                                      – nom
                                                      Jan 27 '15 at 18:32






                                                    • 2





                                                      OP wants to print the content of a LocalDate instance in a specific format. How could SimpleDateFormat help him here?

                                                      – Tom
                                                      Jan 27 '15 at 18:34











                                                    • From what I know, LocalDate is already formatted....

                                                      – nom
                                                      Jan 27 '15 at 18:38











                                                    • @jasko: Use: Date dt = sdf.format(varName);

                                                      – nom
                                                      Jan 27 '15 at 18:40














                                                    -9












                                                    -9








                                                    -9







                                                    A pretty nice way to do this is to use SimpleDateFormat I'll show you how:



                                                    SimpleDateFormat sdf = new SimpleDateFormat("d MMMM YYYY");
                                                    Date d = new Date();
                                                    sdf.format(d);


                                                    I see that you have the date in a variable:



                                                    sdf.format(variable_name);


                                                    Cheers.






                                                    share|improve this answer













                                                    A pretty nice way to do this is to use SimpleDateFormat I'll show you how:



                                                    SimpleDateFormat sdf = new SimpleDateFormat("d MMMM YYYY");
                                                    Date d = new Date();
                                                    sdf.format(d);


                                                    I see that you have the date in a variable:



                                                    sdf.format(variable_name);


                                                    Cheers.







                                                    share|improve this answer












                                                    share|improve this answer



                                                    share|improve this answer










                                                    answered Jan 27 '15 at 18:29









                                                    nomnom

                                                    174314




                                                    174314








                                                    • 1





                                                      SimpleDateFormat can work with LocalDate?

                                                      – Tom
                                                      Jan 27 '15 at 18:30











                                                    • What do you mean by 'can work with'?

                                                      – nom
                                                      Jan 27 '15 at 18:32






                                                    • 2





                                                      OP wants to print the content of a LocalDate instance in a specific format. How could SimpleDateFormat help him here?

                                                      – Tom
                                                      Jan 27 '15 at 18:34











                                                    • From what I know, LocalDate is already formatted....

                                                      – nom
                                                      Jan 27 '15 at 18:38











                                                    • @jasko: Use: Date dt = sdf.format(varName);

                                                      – nom
                                                      Jan 27 '15 at 18:40














                                                    • 1





                                                      SimpleDateFormat can work with LocalDate?

                                                      – Tom
                                                      Jan 27 '15 at 18:30











                                                    • What do you mean by 'can work with'?

                                                      – nom
                                                      Jan 27 '15 at 18:32






                                                    • 2





                                                      OP wants to print the content of a LocalDate instance in a specific format. How could SimpleDateFormat help him here?

                                                      – Tom
                                                      Jan 27 '15 at 18:34











                                                    • From what I know, LocalDate is already formatted....

                                                      – nom
                                                      Jan 27 '15 at 18:38











                                                    • @jasko: Use: Date dt = sdf.format(varName);

                                                      – nom
                                                      Jan 27 '15 at 18:40








                                                    1




                                                    1





                                                    SimpleDateFormat can work with LocalDate?

                                                    – Tom
                                                    Jan 27 '15 at 18:30





                                                    SimpleDateFormat can work with LocalDate?

                                                    – Tom
                                                    Jan 27 '15 at 18:30













                                                    What do you mean by 'can work with'?

                                                    – nom
                                                    Jan 27 '15 at 18:32





                                                    What do you mean by 'can work with'?

                                                    – nom
                                                    Jan 27 '15 at 18:32




                                                    2




                                                    2





                                                    OP wants to print the content of a LocalDate instance in a specific format. How could SimpleDateFormat help him here?

                                                    – Tom
                                                    Jan 27 '15 at 18:34





                                                    OP wants to print the content of a LocalDate instance in a specific format. How could SimpleDateFormat help him here?

                                                    – Tom
                                                    Jan 27 '15 at 18:34













                                                    From what I know, LocalDate is already formatted....

                                                    – nom
                                                    Jan 27 '15 at 18:38





                                                    From what I know, LocalDate is already formatted....

                                                    – nom
                                                    Jan 27 '15 at 18:38













                                                    @jasko: Use: Date dt = sdf.format(varName);

                                                    – nom
                                                    Jan 27 '15 at 18:40





                                                    @jasko: Use: Date dt = sdf.format(varName);

                                                    – nom
                                                    Jan 27 '15 at 18:40


















                                                    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%2f28177370%2fhow-to-format-localdate-to-string%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

                                                    Costa Masnaga

                                                    Fotorealismo

                                                    Sidney Franklin