z_F4JInternalStringUtil { public static String formatISO8601Datetime(Calendar cal) { SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ"); df.setTimeZone(cal.getTimeZone()); return df.format(cal.getTime()); } private  z_F4JInternalStringUtil(); static String maskString(String str); static String join(int[] follows); static String join(long[] follows); static String join(String[] track); static String join(String[] track, String separator); static String formatISO8601Datetime(Calendar cal);  }
@Test public void formatISO8601Datetime() throws Exception { Calendar cal = Calendar.getInstance(); cal.set(Calendar.YEAR, 2012); cal.set(Calendar.MONTH, 5); cal.set(Calendar.DAY_OF_MONTH, 15); cal.set(Calendar.HOUR_OF_DAY, 16); cal.set(Calendar.MINUTE, 17); cal.set(Calendar.SECOND, 18); cal.set(Calendar.MILLISECOND, 0); cal.setTimeZone(TimeZone.getTimeZone("JST")); String actual1 = z_F4JInternalStringUtil.formatISO8601Datetime(cal); assertThat(actual1, is("2012-06-15T16:17:18+0900")); cal.setTimeZone(TimeZone.getTimeZone("UTC")); String actual2 = z_F4JInternalStringUtil.formatISO8601Datetime(cal); assertThat(actual2, is("2012-06-15T07:17:18+0000")); JSONObject json = new JSONObject("{\"datetime1\": \"" + actual1 + "\", \"datetime2\": \"" + actual2 + "\"}"); Date d1 = z_F4JInternalParseUtil.getISO8601Datetime("datetime1", json); Date d2 = z_F4JInternalParseUtil.getISO8601Datetime("datetime2", json); assertThat(d1, is(d2)); }