Home Java Javadate Month Format Example



Month Format Example
Posted on: October 13, 2008 at 12:00 AM
This example shows how to format Month using Format class. In this program we use a pattern of special characters to Month format.

Month Format Example

     

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

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 is used for format Date class object into date / time and appends the it into the StringBuffer.

MonthFormat.java

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

public class MonthFormat {

lor="#ffffff">  public static void main(String args[]) throws ParseException {

  String s;
  Format formatter;
  Date date = new Date();
  date.setMonth(0);


  formatter = new SimpleDateFormat("M")// 1
  s = formatter.format(date);
  System.out.println("Month : " + s);

  formatter = new SimpleDateFormat("MM");  // 01
  s = formatter.format(date);
  System.out.println("Month : " + s);

  formatter = new SimpleDateFormat("MMM")// Jan
  s = formatter.format(date);
  System.out.println("Month : " + s);

  formatter = new SimpleDateFormat("MMMM");  
  s = formatter.format(date);
  // January
  System.out.println("Month : " + s);
  }
}

Output:
Month : 1
Month : 01
Month : Jan
Month : January

Download code

Related Tags for Month Format Example:
cclassormformformatcharpatternusingthischaractercharactersshowforexamplecteprogramtoramexamciwsshemonthusepeinrmasmntclspecialspechowproxaxampsspatracishamplaractttssthshopleplpronogro


More Tutorials from this section

Ask Questions?    Discuss: Month Format Example  

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.