Convert String to Date object in Java
Description
The following code shows how to convert String to Date object.
Example
/* w ww. j a v a2 s. com*/
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
public class Main {
public static void main(String[] args) throws Exception{
DateFormat df = new SimpleDateFormat("dd/MM/yyyy");
Date today = df.parse("20/12/2005");
System.out.println("Today = " + df.format(today));
}
}
The code above generates the following result.