3

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

jmj
  • 232,312
  • 42
  • 391
  • 431
Ksice
  • 3,047
  • 9
  • 39
  • 64

3 Answers3

35
DateFormat df = new SimpleDateFormat("dd.MM.yyyy");
Calendar cal  = Calendar.getInstance();
cal.setTime(df.parse(stringInstanceRepresentingDate));
jmj
  • 232,312
  • 42
  • 391
  • 431
1

Try:

SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy");
Calendar calendarDate = Calendar.getInstance();
if (calendarDate!= null) {
strdate = sdf.format(calendarDate.getTime());
}
Lucifer
  • 28,933
  • 23
  • 88
  • 140
Paresh Mayani
  • 125,853
  • 70
  • 238
  • 294
1

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
  • 475
  • 5
  • 20