-4

I have a string like 14-9-2014,I want to convert it as gregorian calendar,I have searched and tried lot many ways but i cant get any solution,So can any one please tell me how to conver it?thank you

user3820044
  • 177
  • 1
  • 3
  • 20
  • possible duplicate of [Convert a string to a GregorianCalendar](http://stackoverflow.com/questions/2331513/convert-a-string-to-a-gregoriancalendar) – 0101100101 Sep 16 '14 at 07:42

2 Answers2

3

Use SimpleDateFormat to parse the date and then assign it to a Calendar.

DateFormat df = new SimpleDateFormat("dd MM yyyy");
Date date = df.parse("14-9-2014");
Calendar cal = Calendar.getInstance();
cal.setTime(date);

The third line could be replaced with:

Calendar cal = new GregorianCalendar();
user229044
  • 232,980
  • 40
  • 330
  • 338
17Coder
  • 81
  • 5
0

Try this:

SimpleDateFormat formatter = new SimpleDateFormat("dd-M-yyyy", context.getResources().getConfiguration().locale);

Date date = formatter.parse("14-9-2014");
Calendar c = new GregorianCalendar();
c.setTime(date);
mol
  • 2,607
  • 4
  • 21
  • 40