Home Java Java-get-example Get Month Name Example
Questions:Ask|Latest


 
 

Share on Google+Share on Google+

Get Month Name Example

Advertisement
In this Example we want to describe you a code that help you in understanding a how to get a 'Get Month Name Example'.

Get Month Name Example

     

In this Example we want to describe you a code that help you in understanding a how to get a 'Get Month Name Example'.For this we have a class name 'GetMonthNameExample'. Inside the main method we declared a String array name month name. This String array variable is initialized with month name values.

1)getInstance ( )  -  This method return you the calendar object with a specific time zone and locale.

2)get(Calendar.Month) - This get  method return you the current month

Finally the System.out.print print the Month name  from String variable month.

GetMonthNameExample.java

import java.util.*;

public class GetMonthNameExample {

  public static void main(String args[]) {

  String[] monthName = {"January""February",
  "March""April""May""June""July",
  "August""September""October""November",
  "December"
  };

  Calendar cal = Calendar.getInstance();
  String month = monthName[cal.get(Calendar.MONTH)];
  System.out.println("Month name: " + month);
  }
}

Output:

Month name: October


Download code
Advertisement

Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: November 6, 2008

Ask Questions?    Discuss: Get Month Name Example   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
Bhavin
August 22, 2011
The above example

That example was bollocks !!! I mean anyone can do that. you meant to give proper solution or shouldn;t at all.
zumbatron
December 15, 2011
Get month name

Much easier: int m = 7; DateFormatSymbols dfs = new DateFormatSymbols(); System.out.println(dfs.getMonths()[m]);
Riddhi Barbhaya
September 11, 2013
Useful for me..

Its Really Nice Example.. For my Big project small this piece of code worked..and I used it somewhere in Project. Thanks a lot..
DMCA.com