I have been looking for exactly the same answer. I have to be backward compatible to the existing date format, which is, like in the example - "2013-04-12T13:38:48+02:00" and my other limitation is that i cannot use any open source libraries other than what is provided with Java 6. Therefore, after not finding the solution here, I came up with this simple conversion technique, which is quite ugly, but i figured out i post it here in case someone needs a quick and dirty solution. If someone knows how to do it better (with the limitations i mentioned), please correct me.
Therefore, to produce the output in the desired format:
private DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
public GregorianCalendar stringToCalendar(String v)
{
// 22 is an idx of last ':', you can replace with v.lastIndex(':') to be neat
String simpleV = v.substring(0, 22).concat(v.substring(23));
GregorianCalendar gc = (GregorianCalendar) df.getCalendar();
gc.setTime(df.parse(simpleV));
return gc;
}
public String calendarToString(GregorianCalendar v)
{
df.setCalendar(v);
String out = df.format(v.getTime());
return out.substring(0, 22).concat(":").concat(out.substring(22)); // read above on '22'
}
Like I said, this is far from perfect, but I did not find anything better..