### Question:
TimestampWithTimezone { public static Date createDate(Calendar initial, Calendar target) { if (target == null) { return createDate(initial); } long time = target.getTimeInMillis(); target = adjustCalendarForDate(initial, target); Date result = normalizeDate(target, true); target.setTimeInMillis(time); return result; }  static Calendar getCalendar(); static void resetCalendar(TimeZone tz); static Timestamp createTimestamp(Calendar initial, Calendar target); static Time createTime(Calendar initial, Calendar target); static Date createDate(Calendar initial, Calendar target); static Time createTime(Calendar target); static Date createDate(Calendar target); static Timestamp createTimestamp(Calendar target); static DateFormat DATETIME_FORMAT; static DateFormat DATE_FORMAT; static DateFormat TIME_FORMAT; }### Answer:
@Test public void testCreateDate() { GregorianCalendar cal_target = new GregorianCalendar(); cal_target.set(2004, Calendar.JUNE, 30, 0, 0, 00); cal_target.set(Calendar.MILLISECOND, 0); Date date = TimestampWithTimezone.createDate(cal_target); Calendar cal = Calendar.getInstance(); cal.setTimeInMillis(date.getTime()); assertThat(cal.get(Calendar.HOUR_OF_DAY), is(0)); assertThat(cal.get(Calendar.MINUTE), is(0)); assertThat(cal.get(Calendar.SECOND), is(0)); assertThat(cal.get(Calendar.MILLISECOND), is(0)); assertThat(cal.get(Calendar.YEAR), is(2004)); assertThat(cal.get(Calendar.MONTH), is(Calendar.JUNE)); assertThat(cal.get(Calendar.DATE), is(30)); }
@Test public void testDateToDateConversion2() { Calendar localTime = Calendar.getInstance(TimeZone.getTimeZone("America/Chicago")); localTime.set(Calendar.MONTH, Calendar.JUNE); localTime.set(Calendar.DAY_OF_MONTH, 22); localTime.set(Calendar.YEAR, 2004); localTime.set(Calendar.HOUR, 23); localTime.set(Calendar.MINUTE, 15); localTime.set(Calendar.SECOND, 20); localTime.set(Calendar.AM_PM, Calendar.PM); Date converted = TimestampWithTimezone.createDate(localTime, Calendar.getInstance(TimeZone.getTimeZone("Europe/London"))); Calendar cal = Calendar.getInstance(); cal.setTime(converted); assertThat(cal.get(Calendar.MILLISECOND), is(0)); }