How convert month number to month short name in java/android

/**
 * @param monthNumber Month Number starts with 0. For <b>January</b> it is <b>0</b> and for <b>December</b> it is <b>11</b>.
 * @return
 */
 public static String getMonthShortName(int monthNumber)
 {
 String monthName="";

 if(monthNumber>=0 && monthNumber<12)
 try
 {
 Calendar calendar = Calendar.getInstance();
 calendar.set(Calendar.MONTH, monthNumber);

 SimpleDateFormat simpleDateFormat = new SimpleDateFormat("MMM");
 simpleDateFormat.setCalendar(calendar);
 monthName = simpleDateFormat.format(calendar.getTime());
 }
 catch (Exception e)
 {
 if(e!=null)
 e.printStackTrace();
 }
 return monthName;
 }
Advertisements

Tags: , , , , , , , ,

About krishjlk

http://www.facebook.com/krishna.kanth.121

One response to “How convert month number to month short name in java/android”

  1. Krishna says :

    Hi Nice example. but problem is when i pass 1 or 2 it is sending Mar only . …. but for 1 it should be Feb right ???

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: