premkumarroyal / MonthAndYearPicker

The month and year picker for Android. Now you can pick month and year or only month or only year.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to get Month name ??

lazy-coder-10 opened this issue · comments

I was trying to get month name. is there any way to get month name without using external code ??

@rohit6027 Right now once the user selects the month and year you will get the month number (Range from 0 to 11). You can use Calendar class or DateFormatSymbols to get the month name.

Ex:

Using Calender Class :

  SimpleDateFormat simpleDateFormat = new SimpleDateFormat("MMMM", Locale.getDefault());
  Calendar calendar=Calendar.getInstance();
  calendar.set(Calendar.MONTH,selectedMonth);
  String selectedMonthName = simpleDateFormat.format(calendar.getTime());
  Log.d(TAG, "selected month name : "+selectedMonthName);

Using DateFormatSymbols :

String[] _monthNames = new DateFormatSymbols(Locale.getDefault()).getMonths();
String selectedMonthName = _monthNames[selectedMonth];
Log.d(TAG, "selected month name : "+selectedMonthName);