DateUtil { public static Date getLocalDateForUTCDate(Date date) { Calendar local = Calendar.getInstance(); int offset = local.getTimeZone().getOffset(local.getTimeInMillis()); GregorianCalendar utc = new GregorianCalendar(); utc.setTimeInMillis(date.getTime()); utc.add(Calendar.MILLISECOND, offset); return utc.getTime(); }  Date getDateFromNow(int days); Date getDateFromNow(int days, int hours, int minutes); static String dateToString(Date date, String dateFromat); Date getDateFromGivenDate(Date date, int days, int hours,int minutes, int second); Date addTimeOffset(Date date, int mins); static Date getUTCDate(); static Date getUTCDate(long epoh); static Date getLocalDateForUTCDate(Date date); static Date stringToDate(String dateString, String dateFromat);  }
@Test public void testGetLocalDateForUTCDate(){ Date dt = new Date(); Calendar local=Calendar.getInstance(); int offset = local.getTimeZone().getOffset(local.getTimeInMillis()); GregorianCalendar utc = new GregorianCalendar(gmtTimeZone); utc.setTimeInMillis(dt.getTime()); utc.add(Calendar.MILLISECOND, offset); Date expectedDate = utc.getTime(); Date actualDate = dateUtil.getLocalDateForUTCDate(dt); Assert.assertEquals(actualDate.getDate(),expectedDate.getDate()); Assert.assertEquals(actualDate.getMinutes(),expectedDate.getMinutes()); Assert.assertEquals(actualDate.getHours(),expectedDate.getHours()); }