HL7DateTimeFormat { public static DateTimeFormatter dateTime() { if (hl7 == null) { hl7 = new DateTimeFormatterBuilder() .appendYear(4, 4) .appendMonthOfYear(2) .appendDayOfMonth(2) .appendHourOfDay(2) .appendMinuteOfHour(2) .appendSecondOfMinute(2) .appendLiteral('.') .appendMillisOfSecond(3) .appendTimeZoneOffset(null, false, 2, 2) .toFormatter(); } return hl7; } protected  HL7DateTimeFormat(); static DateTimeFormatter dateTime(); static DateTimeFormatter forPointInTime(PointInTime t); static DateTimeFormatter forPrecision(Precision p); static PointInTimeFormatter pointInTimeParser(); static PointInTime parse(String text); static PointInTime toPointInTime(String text); static LocalDateTime toLocalDateTime(String text);  }
@Test public void testFormatDateTimeWithTimeZoneOffset() { DateTimeZone tz = DateTimeZone.forID("America/Chicago"); DateTime t = new DateTime(1975, 7, 23, 10, 23, 55, 123, tz); String withTimeZoneOffset = "19750723102355.123" + DateTimeFormat.forPattern("Z").print(t); Assert.assertEquals(withTimeZoneOffset, HL7DateTimeFormat.dateTime().print(t)); }
@Test public void testFormatLocalDateTime() { LocalDateTime t = new LocalDateTime(1975, 7, 23, 10, 23, 55, 123); Assert.assertEquals("19750723102355.123", HL7DateTimeFormat.dateTime().print(t)); }