Year Format Example

This example shows how to format Year using Format class. In this program we use a pattern of special characters to format week day.

Year Format Example

     

This example shows how to format Year using Format class. In this program we use a pattern of special characters to format week day.

Description of the code :

SimpleDateFormat() : SimpleDateFormat class use for formatting and parsing dates. It allows for formatting date into text , parsing text into date and normalization.

format() : This method used for format Date class object into date / time and appends the it into the StringBuffer.

YearFormat.java


import java.text.*;
import java.util.*;

public class YearFormat {

  public static void main(String args[]) {

  String s;
  Format formatter;
  Date date = new Date();

  formatter = new SimpleDateFormat("yy");  // 02
  s = formatter.format(date);
  System.out.println("Year : " + s);

  formatter = new SimpleDateFormat("yyyy");  // 2002
  s = formatter.format(date);
  System.out.println("Year : " + s);
  }
}


Output

Year : 08
Year : 2008

Download code

Advertisements

 

We have 1000s of tutorials on our website. Search Tutorials tutorials on our website.

Share on Google+Share on Google+

Year Format Example

Posted on: October 13, 2008 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Advertisements

 

Discuss: Year Format Example  

Post your Comment


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

Ads

 

Ads