Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Java Java-get-example Java Get Month

Related Tutorials


 
 

Share on Google+Share on Google+

Java Get Month

Advertisement
In the previous Java examples, we have discussed about date functions and how to get the current date and time.

Java Get Month

     

In the previous Java examples, we have discussed about date functions and how to get the current date and time. But in this example, we are going to show the current month of the existing year. This Java get month example is simply going to print the current month name like January, February etc..

For this purpose we have import the java.util.Calendar package in our program. 

 

 

Syntax for Getting the current month in Java

import java.util.Calendar;
 
public class GetMonth
{
  public static void main(String[] args)
  {
  String[] months = {"January""February",
  "March""April""May""June""July",
  "August""September""October""November",
  "December"};
 
  Calendar cal = Calendar.getInstance(); 
  String month = months[cal.get(Calendar.MONTH)];
  System.out.println("Month name: " + month);
  }
}

Output will be displayed as:

Download Source Code

Advertisements

If you enjoyed this post then why not add us on Google+? Add us to your Circles



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: October 15, 2008

Related Tutorials

Discuss: Java Get Month  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:0
DMCA.com