Parse string with format as 21/12/2007 to a date in Java
Description
The following code shows how to parse string with format as 21/12/2007 to a date.
Example
//from ww w . j a va 2s.c o m
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
public class Main {
public static void main(String[] args) throws Exception {
String today = "21/12/2007";
DateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");
Date date = formatter.parse(today);
System.out.println("date = " + date);
}
}
The code above generates the following result.