Question

I want to convert my date "2013-03-04T23:00:00" to "yyyy-MM-dd'T'HH:mm:ss.SSSZ" but I keep getting "2013-03-04'T'23:00:00.000+0000". Any help?

item.getEnd() is a XMLGregorianCalendar by the way.

Calendar calendar  = item.getEnd().toGregorianCalendar();
calendar.setTimeZone(TimeZone.getTimeZone("UTC"));

Date date = calendar.getTime();
DateTime iso8601 = new DateTime(calendar);

iso8601.toString("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
Was it helpful?

Solution

You should just be able to use the ISODateTimeFormat class that is built in to JodaTime. The example in the documentation is:

DateTime dt = new DateTime();
DateTimeFormatter fmt = ISODateTimeFormat.dateTime();
String str = fmt.print(dt);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top