Home Java Java-get-example Java get Year

Related Tutorials


 
 

Share on Google+Share on Google+

Java get Year

Advertisement
In this section, you will learn how to obtain the current year. The Calendar class provides a getInstance() method that returns a Calendar object.

Java get Year

     

In this section, you will learn how to obtain the current year. The Calendar class provides a getInstance()  method that returns a Calendar object. The method cal.get(Calendar.YEAR) will return the current year.

Here is the code of GetYear.java

import java.util.*;
public class GetYear {
  public static void main(String []arg){
  Calendar cal=Calendar.getInstance();
  int year=cal.get(Calendar.YEAR);
  System.out.println("Current Year: "+year );
  }
  }

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: November 1, 2008

Related Tutorials

Discuss: Java get Year   View All Comments

Post your Comment


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