Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Month name as a string

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?

like image 744
Gaby Avatar asked May 31 '11 19:05

Gaby


People also ask

How do you display months in a string?

We will use it like this. SimpleDateFormat("MMM"); Let us see an example. // displaying month in MMMM format SimpleDateFormat simpleformat = new SimpleDateFormat("MMMM"); String strMonth= simpleformat.


1 Answers

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()); 
like image 189
John Avatar answered Sep 28 '22 06:09

John