Month name as a string

Gaby picture Gaby · May 31, 2011 · Viewed 123.8k times · Source

I'm trying to return the name of the month as a String, for instance "May", "September", "November".

I tried:

int month = c.get(Calendar.MONTH);

However, this returns integers (5, 9, 11, respectively). How can I get the month name?

Answer

John picture John · Dec 19, 2011

Use this :

Calendar cal=Calendar.getInstance();
SimpleDateFormat month_date = new SimpleDateFormat("MMMM");
String month_name = month_date.format(cal.getTime());

Month name will contain the full month name,,if you want short month name use this

 SimpleDateFormat month_date = new SimpleDateFormat("MMM");
 String month_name = month_date.format(cal.getTime());