Parsing Date And Time Example

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


 
Ads

Parsing Date And Time Example

     

This example shows how to parsing date and time using Format class. In this program we use a pattern of special characters to time 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.

ParsingDateandTime.java

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

public class ParsingDateandTime {

  public static void main(String args[]) throws Exception {

  String s;
  DateFormat formatter;
  Date date;

  formatter = new SimpleDateFormat("yyyy.MM.dd.HH.mm.ss");
  date = (Dateformatter.parse("2002.01.29.08.36.33");
  s = formatter.format(date);
  System.out.println(s);

  formatter = new SimpleDateFormat("E, dd MMM yyyy HH:mm:ss Z");
  date = (Dateformatter.parse("Tue, 29 jan 2002 22:14:02 -0500");
  s = formatter.format(date);
  System.out.println(s);
  }
}

Output:
2002.01.29.08.36.33
Wed, 30 Jan 2002 08:44:02 +0530

Download code

Advertisements

Ads
Share on Google+Share on Google+

Parsing Date And Time Example

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

Advertisements

Ads
 

Discuss: Parsing Date And Time Example  

Post your Comment


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

Ads

 

Ads