Parsing custom formatted date string into Date object using SimpleDateFormat - Java Date Time

Java examples for Date Time:SimpleDateFormat

Description

Parsing custom formatted date string into Date object using SimpleDateFormat

Demo Code


import java.util.Date;
import java.text.ParseException;
import java.text.SimpleDateFormat;
 
public class Main {
  public static void main(String[] args) {
    SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yy");
    try/*from  ww w.jav a 2  s  .  c  om*/
    {
      Date date = sdf.parse("31/12/06");
      System.out.println(date);
    }
    catch(ParseException pe)
    {
      System.out.println("Parse Exception : " + pe);
    }
  }
}

Result


Related Tutorials