HttpDateUtils { public static String format(Date date) { boolean includeMillis = date.getTime() % 1000 != 0; return RFC3339DateFormat.formatRfc3339(date, includeMillis); }  static String format(Date date);  }
@Test public void format_rfc3339_zeroMillis() { Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT")); cal.set(1985, 3, 12, 23, 20, 50); cal.set(Calendar.MILLISECOND, 0); Date date = cal.getTime(); assertEquals("1985-04-12T23:20:50Z", HttpDateUtils.format(date)); }
@Test public void format_rfc3339_nonZeroMillis() { Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT")); cal.set(1985, 3, 12, 23, 20, 50); cal.set(Calendar.MILLISECOND, 52); Date date = cal.getTime(); assertEquals("1985-04-12T23:20:50.052Z", HttpDateUtils.format(date)); }