Joda DateTime ISODateTimeFormat pattern
It doesn't appear that you can build such a formatter purely from a pattern. The DateTimeFormat doc says:
Zone:
- 'Z' outputs offset without a colon,
- 'ZZ' outputs the offset with a colon,
- 'ZZZ' or more outputs the zone id.
You can build most of the formatter from a pattern and then customise the time zone output like this:
DateTimeFormatter patternFormat = new DateTimeFormatterBuilder()
.appendPattern("yyyy-MM-dd'T'HH:mm:ss.SSS")
.appendTimeZoneOffset("Z", true, 2, 4)
.toFormatter();
But the formatter returns a "Z" in place of +00:00 see this-
See doc again, it said clearly,
The time zone offset is 'Z' for zero, and of the form '±HH:mm' for non-zero.
So this ISO value 2014-06-01T03:02:13.552Z is equivalent to 2014-06-01T03:02:13.552+00:00.
In your code to see non-zero case, try with
DateTime dt = DateTime.now(); //without arg DateTimeZone.UTC;
If you know that your TimeZone will always be DateTimeZone.UTC, then you can inject the Z in the pattern just like the T character has been injected. Something like this:
DateTimeFormatter patternFormat = DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
If you want to have the same format but without the milliseconds, the pattern might look something like this:
DateTimeFormatter patternFormat = DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ss'Z'");
I am sure you have found this page, but see the Joda Time Formatting reference page for details regarding these formats and other options.