DateTimeUtils { public synchronized static Date getMinutesLaterThan(Date date, int minute) { Calendar cal = Calendar.getInstance(); cal.setTime(date); cal.add(Calendar.MINUTE, minute); return cal.getTime(); }  static String currentTimeAsString(); static String timeAsString(Date date); static String timeAsString(long timeMilli); synchronized static Date getHoursLaterDate(int hours); synchronized static Date getMinutesLaterThan(Date date, int minute); synchronized static Date getSecondsLaterThan(Date date, int second); static Date getHoursBeforeDate(Date date, int hours); static Date getNearestHour(); static String format; }
@Test public void testGetMinutesLasterDate() throws Exception { Date now = new Date(); Date after = DateTimeUtils.getMinutesLaterThan(new Date(), 1); long duration = after.getTime() - now.getTime(); Assert.assertTrue((Math.abs(TimeUnit.MINUTES.toMillis(1L) - duration) < TimeUnit.SECONDS.toMillis(1))); after = DateTimeUtils.getMinutesLaterThan(new Date(), 15); duration = after.getTime() - now.getTime(); Assert.assertTrue((Math.abs(TimeUnit.MINUTES.toMillis(15L) - duration) < TimeUnit.SECONDS.toMillis(1))); }