DateHelper { public static Date setTime(Date date, Date time) { Calendar cal = getEmptyCalendar(); cal.setTime(date); Calendar calTime = getEmptyCalendar(); calTime.setTime(time); cal.set(Calendar.HOUR_OF_DAY, calTime.get(Calendar.HOUR_OF_DAY)); cal.set(Calendar.MINUTE, calTime.get(Calendar.MINUTE)); cal.set(Calendar.SECOND, calTime.get(Calendar.SECOND)); cal.set(Calendar.MILLISECOND, calTime.get(Calendar.MILLISECOND)); return cal.getTime(); } private  DateHelper(); static String format(Date dt); static String format(Date dt, String pattern); static String formatShortDate(Date dt); static String formatShortTime(Date dt); static String formatISO8601(Date dt); static Calendar getEmptyCalendar(); static Calendar calendar(int year, int month, int day); static Date date(int year, int month, int day); static Date beginOfDay(Date dt); static Date endOfDay(Date dt); static int diffDays(Date dtEnd, Date dtBegin); static Date setTime(Date date, Date time); static Date getTime(Date datetime); static boolean isOnlyTime(Date dt); static boolean isOnlyDate(Date dt); static Date addDays(Date date, int count); static boolean isEmpty(Date date); static String[] getWeekdays(); static String[] getShortWeekdays(); static int[] getIndexWeekdays(); static final String DATE_FORMAT_ISO8601; }
@Test public void testSetTime() throws Exception { Calendar cal = Calendar.getInstance(); Date date = new Date(114, 3, 1, 10, 30); Date dateResult = DateHelper.setTime(cal.getTime(), date); assertEquals(10, date.getHours()); assertEquals(30, date.getMinutes()); assertEquals(0, date.getSeconds()); }