Java Date Conversion
String to Date
java.text.SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy");
java.util.Date date = df.parse("21/06/2003");
Date to String
String s = df.format(date);
Create a date
java.util.GregorianCalendar calendar = new GregorianCalendar(2002, 5, 8); // 2002-Jun-08
java.util.Date date = calendar.getTime();
Note that month is zero based. I.e. January = 0, December = 11
java.sql.Date date = new java.sql.Date(new GregorianCalendar(2003, 00, 01).getTime().getTime());
Resources
-- Frank Dean - 05 September 2003
Related Topics: DevelopmentSetup, JavaCodeSnippets