@Test public void shouldCovertToIsoString() { Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("UTC")); cal.set(1970, 0, 1, 0, 0, 0); the(Convert.toIsoString(cal.getTime())).shouldBeEqual("1970-01-01T00:00:00Z"); cal.set(1912, 5, 23, 2, 15, 47); the(Convert.toIsoString(cal.getTime())).shouldBeEqual("1912-06-23T02:15:47Z"); cal.set(2014, 11, 31, 23, 59, 59); the(Convert.toIsoString(cal.getTime())).shouldBeEqual("2014-12-31T23:59:59Z"); }
public static String toIsoString(java.util.Date date) { if (date == null) { return null; } else if (date instanceof java.sql.Date) { return date.toString(); } Calendar cal = THREADLOCAL_CAL_UTC.get(); cal.setTime(date); int year = cal.get(Calendar.YEAR); int month = cal.get(Calendar.MONTH) + 1; int day = cal.get(Calendar.DAY_OF_MONTH); int hour = cal.get(Calendar.HOUR_OF_DAY); int minute = cal.get(Calendar.MINUTE); int second = cal.get(Calendar.SECOND); char[] buf = new char[20]; buf[0] = Character.forDigit(year/1000, 10); buf[1] = Character.forDigit((year/100)%10, 10); buf[2] = Character.forDigit((year/10)%10, 10); buf[3] = Character.forDigit(year%10, 10); buf[4] = '-'; buf[5] = Character.forDigit(month/10, 10); buf[6] = Character.forDigit(month%10, 10); buf[7] = '-'; buf[8] = Character.forDigit(day/10, 10); buf[9] = Character.forDigit(day%10, 10); buf[10] = 'T'; buf[11] = Character.forDigit(hour/10, 10); buf[12] = Character.forDigit(hour%10, 10); buf[13] = ':'; buf[14] = Character.forDigit(minute/10, 10); buf[15] = Character.forDigit(minute%10, 10); buf[16] = ':'; buf[17] = Character.forDigit(second/10, 10); buf[18] = Character.forDigit(second%10, 10); buf[19] = 'Z'; return new String(buf); }
Convert { public static String toIsoString(java.util.Date date) { if (date == null) { return null; } else if (date instanceof java.sql.Date) { return date.toString(); } Calendar cal = THREADLOCAL_CAL_UTC.get(); cal.setTime(date); int year = cal.get(Calendar.YEAR); int month = cal.get(Calendar.MONTH) + 1; int day = cal.get(Calendar.DAY_OF_MONTH); int hour = cal.get(Calendar.HOUR_OF_DAY); int minute = cal.get(Calendar.MINUTE); int second = cal.get(Calendar.SECOND); char[] buf = new char[20]; buf[0] = Character.forDigit(year/1000, 10); buf[1] = Character.forDigit((year/100)%10, 10); buf[2] = Character.forDigit((year/10)%10, 10); buf[3] = Character.forDigit(year%10, 10); buf[4] = '-'; buf[5] = Character.forDigit(month/10, 10); buf[6] = Character.forDigit(month%10, 10); buf[7] = '-'; buf[8] = Character.forDigit(day/10, 10); buf[9] = Character.forDigit(day%10, 10); buf[10] = 'T'; buf[11] = Character.forDigit(hour/10, 10); buf[12] = Character.forDigit(hour%10, 10); buf[13] = ':'; buf[14] = Character.forDigit(minute/10, 10); buf[15] = Character.forDigit(minute%10, 10); buf[16] = ':'; buf[17] = Character.forDigit(second/10, 10); buf[18] = Character.forDigit(second%10, 10); buf[19] = 'Z'; return new String(buf); } }
Convert { public static String toIsoString(java.util.Date date) { if (date == null) { return null; } else if (date instanceof java.sql.Date) { return date.toString(); } Calendar cal = THREADLOCAL_CAL_UTC.get(); cal.setTime(date); int year = cal.get(Calendar.YEAR); int month = cal.get(Calendar.MONTH) + 1; int day = cal.get(Calendar.DAY_OF_MONTH); int hour = cal.get(Calendar.HOUR_OF_DAY); int minute = cal.get(Calendar.MINUTE); int second = cal.get(Calendar.SECOND); char[] buf = new char[20]; buf[0] = Character.forDigit(year/1000, 10); buf[1] = Character.forDigit((year/100)%10, 10); buf[2] = Character.forDigit((year/10)%10, 10); buf[3] = Character.forDigit(year%10, 10); buf[4] = '-'; buf[5] = Character.forDigit(month/10, 10); buf[6] = Character.forDigit(month%10, 10); buf[7] = '-'; buf[8] = Character.forDigit(day/10, 10); buf[9] = Character.forDigit(day%10, 10); buf[10] = 'T'; buf[11] = Character.forDigit(hour/10, 10); buf[12] = Character.forDigit(hour%10, 10); buf[13] = ':'; buf[14] = Character.forDigit(minute/10, 10); buf[15] = Character.forDigit(minute%10, 10); buf[16] = ':'; buf[17] = Character.forDigit(second/10, 10); buf[18] = Character.forDigit(second%10, 10); buf[19] = 'Z'; return new String(buf); } private  Convert(); }
Convert { public static String toIsoString(java.util.Date date) { if (date == null) { return null; } else if (date instanceof java.sql.Date) { return date.toString(); } Calendar cal = THREADLOCAL_CAL_UTC.get(); cal.setTime(date); int year = cal.get(Calendar.YEAR); int month = cal.get(Calendar.MONTH) + 1; int day = cal.get(Calendar.DAY_OF_MONTH); int hour = cal.get(Calendar.HOUR_OF_DAY); int minute = cal.get(Calendar.MINUTE); int second = cal.get(Calendar.SECOND); char[] buf = new char[20]; buf[0] = Character.forDigit(year/1000, 10); buf[1] = Character.forDigit((year/100)%10, 10); buf[2] = Character.forDigit((year/10)%10, 10); buf[3] = Character.forDigit(year%10, 10); buf[4] = '-'; buf[5] = Character.forDigit(month/10, 10); buf[6] = Character.forDigit(month%10, 10); buf[7] = '-'; buf[8] = Character.forDigit(day/10, 10); buf[9] = Character.forDigit(day%10, 10); buf[10] = 'T'; buf[11] = Character.forDigit(hour/10, 10); buf[12] = Character.forDigit(hour%10, 10); buf[13] = ':'; buf[14] = Character.forDigit(minute/10, 10); buf[15] = Character.forDigit(minute%10, 10); buf[16] = ':'; buf[17] = Character.forDigit(second/10, 10); buf[18] = Character.forDigit(second%10, 10); buf[19] = 'Z'; return new String(buf); } private  Convert(); static String toString(Object value); static Boolean toBoolean(Object value); static java.sql.Date toSqlDate(Object value); static java.sql.Date truncateToSqlDate(Object value); static java.sql.Date truncateToSqlDate(long time); static String toIsoString(java.util.Date date); static Double toDouble(Object value); static java.sql.Time toTime(Object value); static java.sql.Timestamp toTimestamp(Object value); static Float toFloat(Object value); static Long toLong(Object value); static Integer toInteger(Object value); static BigDecimal toBigDecimal(Object value); static byte[] toBytes(Object value); static byte[] toBytes(Blob blob); static Short toShort(Object value); }
Convert { public static String toIsoString(java.util.Date date) { if (date == null) { return null; } else if (date instanceof java.sql.Date) { return date.toString(); } Calendar cal = THREADLOCAL_CAL_UTC.get(); cal.setTime(date); int year = cal.get(Calendar.YEAR); int month = cal.get(Calendar.MONTH) + 1; int day = cal.get(Calendar.DAY_OF_MONTH); int hour = cal.get(Calendar.HOUR_OF_DAY); int minute = cal.get(Calendar.MINUTE); int second = cal.get(Calendar.SECOND); char[] buf = new char[20]; buf[0] = Character.forDigit(year/1000, 10); buf[1] = Character.forDigit((year/100)%10, 10); buf[2] = Character.forDigit((year/10)%10, 10); buf[3] = Character.forDigit(year%10, 10); buf[4] = '-'; buf[5] = Character.forDigit(month/10, 10); buf[6] = Character.forDigit(month%10, 10); buf[7] = '-'; buf[8] = Character.forDigit(day/10, 10); buf[9] = Character.forDigit(day%10, 10); buf[10] = 'T'; buf[11] = Character.forDigit(hour/10, 10); buf[12] = Character.forDigit(hour%10, 10); buf[13] = ':'; buf[14] = Character.forDigit(minute/10, 10); buf[15] = Character.forDigit(minute%10, 10); buf[16] = ':'; buf[17] = Character.forDigit(second/10, 10); buf[18] = Character.forDigit(second%10, 10); buf[19] = 'Z'; return new String(buf); } private  Convert(); static String toString(Object value); static Boolean toBoolean(Object value); static java.sql.Date toSqlDate(Object value); static java.sql.Date truncateToSqlDate(Object value); static java.sql.Date truncateToSqlDate(long time); static String toIsoString(java.util.Date date); static Double toDouble(Object value); static java.sql.Time toTime(Object value); static java.sql.Timestamp toTimestamp(Object value); static Float toFloat(Object value); static Long toLong(Object value); static Integer toInteger(Object value); static BigDecimal toBigDecimal(Object value); static byte[] toBytes(Object value); static byte[] toBytes(Blob blob); static Short toShort(Object value);  }