Wednesday, February 13, 2008

Convert String to Date

DateFormat df = new SimpleDateFormat("dd-MM-yyyy");

DateFormat df1 = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");

try
{
Date today = df.parse("20-12-2005");
Date t1 = df1.parse("2008-05-12 08:40:00");


System.out.println("Today = " + df.format(today));
System.out.println("t1 = " + df1.format(t1));

System.out.println(t1);
} catch (ParseException e)
{
e.printStackTrace();
}

No comments :