How to display month name from DatePickerDialog - Android Studio











up vote
0
down vote

favorite












Hi I would like to display the month name when I click in my DatePickerDialog but it's display the month number



Here is my code



tvDate.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {

int day = calendar.get(Calendar.DAY_OF_WEEK);
int month = calendar.get(Calendar.MONTH);
int year = calendar.get(Calendar.YEAR);

dpd = new DatePickerDialog(getActivity(), new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker datePicker, int nYear, int nMonth, int nDay) {
calendar.getDisplayName(Calendar.MONTH, Calendar.SHORT, Locale.getDefault());
tvDate.setText(nDay + "/" + (nMonth+1) + "/" + nYear);
}
}, year, month, day);
dpd.show();
}
});









share|improve this question


























    up vote
    0
    down vote

    favorite












    Hi I would like to display the month name when I click in my DatePickerDialog but it's display the month number



    Here is my code



    tvDate.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {

    int day = calendar.get(Calendar.DAY_OF_WEEK);
    int month = calendar.get(Calendar.MONTH);
    int year = calendar.get(Calendar.YEAR);

    dpd = new DatePickerDialog(getActivity(), new DatePickerDialog.OnDateSetListener() {
    @Override
    public void onDateSet(DatePicker datePicker, int nYear, int nMonth, int nDay) {
    calendar.getDisplayName(Calendar.MONTH, Calendar.SHORT, Locale.getDefault());
    tvDate.setText(nDay + "/" + (nMonth+1) + "/" + nYear);
    }
    }, year, month, day);
    dpd.show();
    }
    });









    share|improve this question
























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      Hi I would like to display the month name when I click in my DatePickerDialog but it's display the month number



      Here is my code



      tvDate.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View view) {

      int day = calendar.get(Calendar.DAY_OF_WEEK);
      int month = calendar.get(Calendar.MONTH);
      int year = calendar.get(Calendar.YEAR);

      dpd = new DatePickerDialog(getActivity(), new DatePickerDialog.OnDateSetListener() {
      @Override
      public void onDateSet(DatePicker datePicker, int nYear, int nMonth, int nDay) {
      calendar.getDisplayName(Calendar.MONTH, Calendar.SHORT, Locale.getDefault());
      tvDate.setText(nDay + "/" + (nMonth+1) + "/" + nYear);
      }
      }, year, month, day);
      dpd.show();
      }
      });









      share|improve this question













      Hi I would like to display the month name when I click in my DatePickerDialog but it's display the month number



      Here is my code



      tvDate.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View view) {

      int day = calendar.get(Calendar.DAY_OF_WEEK);
      int month = calendar.get(Calendar.MONTH);
      int year = calendar.get(Calendar.YEAR);

      dpd = new DatePickerDialog(getActivity(), new DatePickerDialog.OnDateSetListener() {
      @Override
      public void onDateSet(DatePicker datePicker, int nYear, int nMonth, int nDay) {
      calendar.getDisplayName(Calendar.MONTH, Calendar.SHORT, Locale.getDefault());
      tvDate.setText(nDay + "/" + (nMonth+1) + "/" + nYear);
      }
      }, year, month, day);
      dpd.show();
      }
      });






      java android datepicker






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 11 at 15:27









      Eduardo Noyola

      435




      435
























          2 Answers
          2






          active

          oldest

          votes

















          up vote
          1
          down vote



          accepted










          You can format the date you get from DatePickerDialog to display the name of the month:



          public void onDateSet(DatePicker datePicker, int nYear, int nMonth, int nDay) {
          SimpleDateFormat sdf = new SimpleDateFormat("dd/MMMM/yyyy");
          calendar.set(nYear, nMonth, nDay);
          String dateString = sdf.format(calendar.getTime());
          tvDate.setText(dateString);
          }





          share|improve this answer























          • Thanks! This works for me!
            – Eduardo Noyola
            Nov 11 at 16:24


















          up vote
          1
          down vote













          There are two ways of getting month name



          Method 1



          public static final String MONTHS = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};


          use an array and get the String by MONTHS[monthNumber].
          Ref



          Method 2
          Setting the current date in the Calendar and getting back the month like this:



              @Override
          public void onDateSet(DatePicker datePicker, int nYear, int nMonth, int nDay) {
          calendar.set(Calendar.DAY_OF_MONTH,nDay);
          calendar.set(Calendar.MONTH,nMonth);
          calendar.set(Calendar.YEAR,mYear);
          calendar.getDisplayName(Calendar.MONTH, Calendar.SHORT, Locale.getDefault());
          tvDate.setText(nDay + "/" + (nMonth+1) + "/" + nYear);
          }


          In my personal opinion, I would recommend the Method 1






          share|improve this answer





















            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',
            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%2f53250220%2fhow-to-display-month-name-from-datepickerdialog-android-studio%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








            up vote
            1
            down vote



            accepted










            You can format the date you get from DatePickerDialog to display the name of the month:



            public void onDateSet(DatePicker datePicker, int nYear, int nMonth, int nDay) {
            SimpleDateFormat sdf = new SimpleDateFormat("dd/MMMM/yyyy");
            calendar.set(nYear, nMonth, nDay);
            String dateString = sdf.format(calendar.getTime());
            tvDate.setText(dateString);
            }





            share|improve this answer























            • Thanks! This works for me!
              – Eduardo Noyola
              Nov 11 at 16:24















            up vote
            1
            down vote



            accepted










            You can format the date you get from DatePickerDialog to display the name of the month:



            public void onDateSet(DatePicker datePicker, int nYear, int nMonth, int nDay) {
            SimpleDateFormat sdf = new SimpleDateFormat("dd/MMMM/yyyy");
            calendar.set(nYear, nMonth, nDay);
            String dateString = sdf.format(calendar.getTime());
            tvDate.setText(dateString);
            }





            share|improve this answer























            • Thanks! This works for me!
              – Eduardo Noyola
              Nov 11 at 16:24













            up vote
            1
            down vote



            accepted







            up vote
            1
            down vote



            accepted






            You can format the date you get from DatePickerDialog to display the name of the month:



            public void onDateSet(DatePicker datePicker, int nYear, int nMonth, int nDay) {
            SimpleDateFormat sdf = new SimpleDateFormat("dd/MMMM/yyyy");
            calendar.set(nYear, nMonth, nDay);
            String dateString = sdf.format(calendar.getTime());
            tvDate.setText(dateString);
            }





            share|improve this answer














            You can format the date you get from DatePickerDialog to display the name of the month:



            public void onDateSet(DatePicker datePicker, int nYear, int nMonth, int nDay) {
            SimpleDateFormat sdf = new SimpleDateFormat("dd/MMMM/yyyy");
            calendar.set(nYear, nMonth, nDay);
            String dateString = sdf.format(calendar.getTime());
            tvDate.setText(dateString);
            }






            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Nov 11 at 16:12

























            answered Nov 11 at 16:04









            forpas

            5,5431217




            5,5431217












            • Thanks! This works for me!
              – Eduardo Noyola
              Nov 11 at 16:24


















            • Thanks! This works for me!
              – Eduardo Noyola
              Nov 11 at 16:24
















            Thanks! This works for me!
            – Eduardo Noyola
            Nov 11 at 16:24




            Thanks! This works for me!
            – Eduardo Noyola
            Nov 11 at 16:24












            up vote
            1
            down vote













            There are two ways of getting month name



            Method 1



            public static final String MONTHS = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};


            use an array and get the String by MONTHS[monthNumber].
            Ref



            Method 2
            Setting the current date in the Calendar and getting back the month like this:



                @Override
            public void onDateSet(DatePicker datePicker, int nYear, int nMonth, int nDay) {
            calendar.set(Calendar.DAY_OF_MONTH,nDay);
            calendar.set(Calendar.MONTH,nMonth);
            calendar.set(Calendar.YEAR,mYear);
            calendar.getDisplayName(Calendar.MONTH, Calendar.SHORT, Locale.getDefault());
            tvDate.setText(nDay + "/" + (nMonth+1) + "/" + nYear);
            }


            In my personal opinion, I would recommend the Method 1






            share|improve this answer

























              up vote
              1
              down vote













              There are two ways of getting month name



              Method 1



              public static final String MONTHS = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};


              use an array and get the String by MONTHS[monthNumber].
              Ref



              Method 2
              Setting the current date in the Calendar and getting back the month like this:



                  @Override
              public void onDateSet(DatePicker datePicker, int nYear, int nMonth, int nDay) {
              calendar.set(Calendar.DAY_OF_MONTH,nDay);
              calendar.set(Calendar.MONTH,nMonth);
              calendar.set(Calendar.YEAR,mYear);
              calendar.getDisplayName(Calendar.MONTH, Calendar.SHORT, Locale.getDefault());
              tvDate.setText(nDay + "/" + (nMonth+1) + "/" + nYear);
              }


              In my personal opinion, I would recommend the Method 1






              share|improve this answer























                up vote
                1
                down vote










                up vote
                1
                down vote









                There are two ways of getting month name



                Method 1



                public static final String MONTHS = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};


                use an array and get the String by MONTHS[monthNumber].
                Ref



                Method 2
                Setting the current date in the Calendar and getting back the month like this:



                    @Override
                public void onDateSet(DatePicker datePicker, int nYear, int nMonth, int nDay) {
                calendar.set(Calendar.DAY_OF_MONTH,nDay);
                calendar.set(Calendar.MONTH,nMonth);
                calendar.set(Calendar.YEAR,mYear);
                calendar.getDisplayName(Calendar.MONTH, Calendar.SHORT, Locale.getDefault());
                tvDate.setText(nDay + "/" + (nMonth+1) + "/" + nYear);
                }


                In my personal opinion, I would recommend the Method 1






                share|improve this answer












                There are two ways of getting month name



                Method 1



                public static final String MONTHS = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};


                use an array and get the String by MONTHS[monthNumber].
                Ref



                Method 2
                Setting the current date in the Calendar and getting back the month like this:



                    @Override
                public void onDateSet(DatePicker datePicker, int nYear, int nMonth, int nDay) {
                calendar.set(Calendar.DAY_OF_MONTH,nDay);
                calendar.set(Calendar.MONTH,nMonth);
                calendar.set(Calendar.YEAR,mYear);
                calendar.getDisplayName(Calendar.MONTH, Calendar.SHORT, Locale.getDefault());
                tvDate.setText(nDay + "/" + (nMonth+1) + "/" + nYear);
                }


                In my personal opinion, I would recommend the Method 1







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 11 at 15:46









                Burhanuddin Rashid

                3,37852140




                3,37852140






























                    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.





                    Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                    Please pay close attention to the following guidance:


                    • 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%2f53250220%2fhow-to-display-month-name-from-datepickerdialog-android-studio%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

                    Coverage of Google Street View

                    Full-time equivalent

                    Surfing