converting String to Calendar. What is the easiest way?
71,234
Solution 1
DateFormat df = new SimpleDateFormat("dd.MM.yyyy");
Calendar cal = Calendar.getInstance();
cal.setTime(df.parse(stringInstanceRepresentingDate));
Solution 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)
Solution 3
Try:
SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy");
Calendar calendarDate = Calendar.getInstance();
if (calendarDate!= null) {
strdate = sdf.format(calendarDate.getTime());
}
Author by
Ksice
Updated on August 07, 2020Comments
-
Ksice over 3 years
What is the simplest and easiest way to convert formatted String to Calendar? For example 'dd.MM.yyyy' to Calendar?