DateUtils { public static Date convertToUserDate(String userTimeZone, Date serverDate) { TimeZone userLocal = TimeZone.getTimeZone(userTimeZone); int rawOffset = userLocal.getRawOffset() - TimeZone.getDefault().getRawOffset(); return new Date(serverDate.getTime() + rawOffset); }  static long getCollectTimeInLong(Date date); static Date convertToServerDate(String userTimeZone, Date userDate); static Date convertToUserDate(String userTimeZone, Date serverDate); static String dateToString(Date date); static Map<String, String> getFilteredTimeZoneMap(); static Date toSimpleDate(String strDate); static Date toDate(String strDate); static Date addDay(Date date, int days); static String ms2Time(long ms); static long timeToMs(int day, int hour, int min, int sec); static boolean compareDateEndWithMinute(Date d1, Date d2);  }
@Test public void testConvertToUserDate() { String userLocaleId = "Asia/Seoul"; TimeZone tz = TimeZone.getTimeZone(userLocaleId); Date serverDate = new Date(); Date userDate = DateUtils.convertToUserDate(userLocaleId, serverDate); assertThat((int) (userDate.getTime() - serverDate.getTime()), is(tz.getRawOffset() - TimeZone.getDefault().getRawOffset())); Date newServerDate = DateUtils.convertToServerDate(userLocaleId, userDate); assertThat(serverDate.getTime(), is(newServerDate.getTime())); }