TiTATimeConverter { public static Long getString2Duration(String time) throws ParseException { String[] timeArray = time.split(":"); if (timeArray.length != C_THREE) { throw new ParseException("", 0); } try { long millis; millis = Integer.parseInt(timeArray[0]) * C_THREETHOUSANDSIXHUNDRET; millis += Integer.parseInt(timeArray[1]) * C_SIXTY; millis += Integer.parseInt(timeArray[2]); millis *= C_THOUSAND; return millis; } catch (NumberFormatException e) { throw new ParseException("", 1); } }  static String getDuration2String(Long time); static Long getString2Duration(String time); static Long getMillisFromHour(Long hour);  }
@Test public void testGetString2Duration() throws ParseException { GregorianCalendar c1 = new GregorianCalendar(); GregorianCalendar c2 = new GregorianCalendar(); c1.set(2009, GregorianCalendar.JANUARY, 10, 10, 23, 15); c2.set(2009, GregorianCalendar.JANUARY, 10, 0, 0, 0); Long l = c1.getTimeInMillis() - c2.getTimeInMillis(); String s = TiTATimeConverter.getDuration2String(l); assertEquals("10:23:15", s); }