This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes Java in General and the fly likes How to get month name Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "How to get month name" Watch "How to get month name" New topic
Author

How to get month name

ram gaurav
Ranch Hand

Joined: Mar 29, 2006
Posts: 208
HI

Like i have an integer value 1.

Now i want to get month which come at place of 1, as months started from 0 , like 0 means Janurary, so 1 means February.

Is there any method where i can pass the integer value and get back the month name.
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

No. You'll have to do this translation yourself. Calendars only hold the value of the time, how it is displayed is seperate. Have a look at java.text.SimpleDateFormat for a starter as to how to apply a format to your date.
[ January 24, 2007: Message edited by: Paul Sturrock ]

JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 13868
    
  10

You can do it simply like this:

- Create an array of strings containing the names of the months.
- Use the integer as an index in the array to lookup the name of the month.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
ram gaurav
Ranch Hand

Joined: Mar 29, 2006
Posts: 208
Thanks a lot.
Ajay Singh
Ranch Hand

Joined: Dec 13, 2006
Posts: 182
You can use SimpleDateFormat to get the string

Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
another option

System.out.println(new java.text.DateFormatSymbols().getMonths()[1]);
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to get month name
 
Similar Threads
Need explanation about three dimensional arrays
Using an int to hold a four digit date
Bitwise inversion of 0
Whats wrong with tis line (Calender related)
Need help in data displaying