How to convert a date String to a Date or Calendar object?
DateFormat formatter = new SimpleDateFormat("MM/dd/yy");
Date date = formatter.parse("01/29/02");
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
Sample Program:
import java.util.*;
import java.text.*;
public class DateToCalender {
public static void main(String[] args) {
try { String str_date="11-June-07";
DateFormat formatter ;
Date date ;
formatter = new SimpleDateFormat("dd-MMM-yy");
date = (Date)formatter.parse(str_date);
Calendar cal=Calendar.getInstance();
cal.setTime(date);
System.out.println("Today is " +cal );
}
catch (ParseException e)
{System.out.println("Exception :"+e); }
}
}