Convert a String Date Such as 2003/01/10 into a java.util.Date Object in Java
Description
The following code shows how to convert a String Date Such as 2003/01/10 into a java.util.Date Object.
Example
/*from ww w . j av a 2 s. c om*/
import java.text.ParseException;
import java.text.SimpleDateFormat;
public class Main {
public static void main(String[] args) {
SimpleDateFormat formatter = new SimpleDateFormat("yyyy/MM/dd");
String date = "2003/01/10";
java.util.Date utilDate = null;
try {
utilDate = formatter.parse(date);
} catch (ParseException e) {
e.printStackTrace();
}
System.out.println("date:" + date);
System.out.println("utilDate:" + utilDate);
}
}
The code above generates the following result.