I am trying to get time stamp in this format: 2016-06-07T14:51:15+00:00
I tried multiple ways as suggested but nothing seems to work. Below are few attempts I made and the outcome.
Trail-1:
DatatypeConverter.printDateTime(new GregorianCalendar(Locale.US));
output: 2016-09-29T10:55:12.572-05:00 ( problem: getting milli seconds. I don't want milliseconds )
Trail-2:
SimpleDateFormat sdfDate = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
output: 2016-09-29T10:56:57-0500 ( problem: offset is missing colon)
Trail-3:
SimpleDateFormat sdfDate = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZZ");
Date now = new Date();
String strDate = sdfDate.format(now);
Output: 2016-09-29T10:58:24.764-0500 (problem: offset is missing colon)
None of the existing stackoverflow questions on this issue can solve my problem. I am using Java 7. I don't want to use any library like Joda etc..