Home Java Java-get-example Java get year from date



Java get year from date
Posted on: November 1, 2008 at 12:00 AM
In this section you will study how to retrieve the year from the date. You can see in the given example that we have called SimpleDateFormat class showing the format of year.

Java get year from date

     

In this section you will study how to retrieve the year from the date. You can see in the given example that we have called SimpleDateFormat class showing the format of year. The method simpleDateformat.format(date) formats a Date into a date/time string and returns the year.

 

 

 

Here is the code of GetYearFromDate

import java.util.*;
import java.text.*;
ss
public class GetYearFromDate{
  public static void main(String[]args){
  Date date = new Date();
  SimpleDateFormat simpleDateformat=new SimpleDateFormat("yyyy");
  System.out.println("Year: " + simpleDateformat.format(date));
}
}

Output will be displayed as:

Download Source Code

Related Tags for Java get year from date:
cstringclassormdateformtimeiomethodformatreturnintthissimpleshowforieexamplecallstudytoexamsheareilsectioncantrieimfromdateformatinrmcalasmnttrcaclretrieveallmehowintoedayearxaxampsurneeatishaimellivmpleaandarstrsimwingssriringthshoavsthatpleplndonomo


More Tutorials from this section

Ask Questions?    Discuss: Java get year from date  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.