Q:

‘Using Java How to convert a date String to a Date or Calendar object?

0

‘Using Java How to convert a date String to a Date or Calendar object?

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

DateFormat formatter = new SimpleDateFormat("MM/dd/yy");
try {
  Date date = formatter.parse("01/29/02");
} catch (ParseException e) {
  e.printStackTrace();
}
See SimpleDateFormat javadoc for more.
And to turn it into a Calendar, do:
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now