What is the simplest and easiest way to convert formatted String to Calendar? For example 'dd.MM.yyyy' to Calendar?
Asked
Active
Viewed 7.4k times
3 Answers
35
DateFormat df = new SimpleDateFormat("dd.MM.yyyy");
Calendar cal = Calendar.getInstance();
cal.setTime(df.parse(stringInstanceRepresentingDate));

jmj
- 237,923
- 42
- 401
- 438
2
Try this piece of code:
String dateStr = "04/05/2010";
SimpleDateFormat curFormater = new SimpleDateFormat("dd/MM/yyyy");
Date dateObj = curFormater.parse(dateStr);
Calendar calendar = Calendar.getInstance();
calendar .setTime(dateObj)

koleanu
- 495
- 5
- 20
1
Try:
SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy");
Calendar calendarDate = Calendar.getInstance();
if (calendarDate!= null) {
strdate = sdf.format(calendarDate.getTime());
}

Lucifer
- 29,392
- 25
- 90
- 143

Paresh Mayani
- 127,700
- 71
- 241
- 295