Convert a string to a GregorianCalendar

Use SimpleDateFormat to parse the date and then assign it to a Calendar.

DateFormat df = new SimpleDateFormat("dd MM yyyy");
Date date = df.parse("02 26 1991");
Calendar cal = Calendar.getInstance();
cal.setTime(date);

The third line could be replaced with:

Calendar cal = new GregorianCalendar();

but I prefer the first version.

Leave a Comment