aspose file tools*
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 Soft Skills this week in the Jobs Discussion 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: 14428
    
  23

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 8 API documentation
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