How to get Month Name from Calendar?

ogzd picture ogzd · Feb 12, 2013 · Viewed 247.6k times · Source

Is there a oneliner to get the name of the month when we know

int monthNumber = calendar.get(Calendar.MONTH)

Or what is the easiest way?

Answer

PermGenError picture PermGenError · Feb 12, 2013

you can achieve it using SimpleDateFormat, which is meant to format date and times.

Calendar cal = Calendar.getInstance();
System.out.println(new SimpleDateFormat("MMM").format(cal.getTime()));