3

What is the simplest and easiest way to convert formatted String to Calendar? For example 'dd.MM.yyyy' to Calendar?

jmj
  • 237,923
  • 42
  • 401
  • 438
Ksice
  • 3,277
  • 9
  • 43
  • 67

3 Answers3

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