@Test public void testGetLastTimeFromDate() { SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd/MM/yyyy"); SimpleDateFormat simpleDateFormatAux = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss"); Date date = null; try { date = simpleDateFormat.parse("01/01/2017"); Date obtainedDate = DateUtils.getLastTimeFromDate(date); String expectedStr = "01/01/2017 23:59:59"; assertThat(simpleDateFormatAux.format(obtainedDate), is(expectedStr)); } catch (ParseException e) { e.printStackTrace(); } }
public static Date getLastTimeFromDate(Date date) { Calendar calendar = Calendar.getInstance(); calendar.setTime(date); calendar.set(Calendar.HOUR_OF_DAY, calendar.getMaximum(Calendar.HOUR_OF_DAY)); calendar.set(Calendar.MINUTE, calendar.getMaximum(Calendar.MINUTE)); calendar.set(Calendar.SECOND, calendar.getMaximum(Calendar.SECOND)); calendar.set(Calendar.MILLISECOND, calendar.getMaximum(Calendar.MILLISECOND)); return calendar.getTime(); }
DateUtils { public static Date getLastTimeFromDate(Date date) { Calendar calendar = Calendar.getInstance(); calendar.setTime(date); calendar.set(Calendar.HOUR_OF_DAY, calendar.getMaximum(Calendar.HOUR_OF_DAY)); calendar.set(Calendar.MINUTE, calendar.getMaximum(Calendar.MINUTE)); calendar.set(Calendar.SECOND, calendar.getMaximum(Calendar.SECOND)); calendar.set(Calendar.MILLISECOND, calendar.getMaximum(Calendar.MILLISECOND)); return calendar.getTime(); } }
DateUtils { public static Date getLastTimeFromDate(Date date) { Calendar calendar = Calendar.getInstance(); calendar.setTime(date); calendar.set(Calendar.HOUR_OF_DAY, calendar.getMaximum(Calendar.HOUR_OF_DAY)); calendar.set(Calendar.MINUTE, calendar.getMaximum(Calendar.MINUTE)); calendar.set(Calendar.SECOND, calendar.getMaximum(Calendar.SECOND)); calendar.set(Calendar.MILLISECOND, calendar.getMaximum(Calendar.MILLISECOND)); return calendar.getTime(); }  }
DateUtils { public static Date getLastTimeFromDate(Date date) { Calendar calendar = Calendar.getInstance(); calendar.setTime(date); calendar.set(Calendar.HOUR_OF_DAY, calendar.getMaximum(Calendar.HOUR_OF_DAY)); calendar.set(Calendar.MINUTE, calendar.getMaximum(Calendar.MINUTE)); calendar.set(Calendar.SECOND, calendar.getMaximum(Calendar.SECOND)); calendar.set(Calendar.MILLISECOND, calendar.getMaximum(Calendar.MILLISECOND)); return calendar.getTime(); }  static String formatCompleteDate(Date date); static String formatOnlyDay(Date date); static String formatFilenameDate(Date date); static String formatDateForMongo(Date date); static String getDuration(Date dateBegin, Date dateEnd); static Date getLastTimeFromDate(Date date); }
DateUtils { public static Date getLastTimeFromDate(Date date) { Calendar calendar = Calendar.getInstance(); calendar.setTime(date); calendar.set(Calendar.HOUR_OF_DAY, calendar.getMaximum(Calendar.HOUR_OF_DAY)); calendar.set(Calendar.MINUTE, calendar.getMaximum(Calendar.MINUTE)); calendar.set(Calendar.SECOND, calendar.getMaximum(Calendar.SECOND)); calendar.set(Calendar.MILLISECOND, calendar.getMaximum(Calendar.MILLISECOND)); return calendar.getTime(); }  static String formatCompleteDate(Date date); static String formatOnlyDay(Date date); static String formatFilenameDate(Date date); static String formatDateForMongo(Date date); static String getDuration(Date dateBegin, Date dateEnd); static Date getLastTimeFromDate(Date date);  }