I have a class which contains a variable
private GregorianCalendar cal;
Now I want to initialize it with a date in yyyy-mm-dd
You can try to use SimpleDateFormat
for example :
GregorianCalendar cal = new GregorianCalendar();
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
format.setCalendar(cal);
String result = format.format(cal.getTime());
System.out.println(result);//today is 2017-05-25
To convert String to GregorianCalendar
:
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ssX");
Date date = format.parse("2017-05-25T14:36:52+03:00");
GregorianCalendar cal2 = new GregorianCalendar();
cal2.setTime(date);