Joda DateTime ISODateTimeFormat pattern

datetime, java, jodatime

Solution

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();

Problem

The Joda ISODateTimeFormat docs say `ISODateTimeFormat.dateTime()` returns a formatter for the pattern yyyy-MM-dd'T'HH:mm:ss.SSSZZ But the formatter returns a "Z" in place of +00:00 see this- ``` DateTime dt = DateTime.now(DateTimeZone.UTC); DateTimeFormatter patternFormat = DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ss.SSSZZ"); DateTimeFormatter isoFormat = ISODateTimeFormat.dateTime(); System.out.println(dt.toString(patternFormat)); //2014-06-01T03:02:13.552+00:00 System.out.println(dt.toString(isoFormat)); //2014-06-01T03:02:13.552Z ``` Can anyone tell me what the pattern would be to get the +00:00 to print as a Z Edit: Just to clarify- I know that the 'Z' is the same as +00:00 but textually it is different. What I am asking is what pattern would place a Z as the time offset instead of +00:00 (Sorry if this is too trivial. I wanted to use the ISO format without milliseconds and in the course of writing this question I found exactly what I was after in `ISODateTimeFormat.dateTimeNoMillis()` so I am asking now only for interests sake)

Original source