Set date to the end of a minute


import java.util.Calendar;
import java.util.Date;

public class Main {
  public static void main(String[] argv) {
    System.out.println(getEndOfMinute(new Date()));
  }

  public static Date getEndOfMinute(Date day) {
    return getEndOfMinute(day, Calendar.getInstance());
  }

  public static Date getEndOfMinute(Date day, Calendar cal) {
    if (day == null || cal == null) {
      return day;
    }

    cal.setTime(day);
    cal.set(Calendar.SECOND, cal.getMaximum(Calendar.SECOND));
    cal.set(Calendar.MILLISECOND, cal.getMaximum(Calendar.MILLISECOND));
    return cal.getTime();
  }
}
Home 
  Java Book 
    Runnable examples  

Date Set:
  1. Set Date to Noon
  2. Set Date to the first millisecond of the day, just after midnight.
  3. Set Date to the first millisecond of the month, just after midnight.
  4. Set Date to the last millisecond of the day, just before midnight.
  5. Set Date to the last millisecond of the minute.
  6. Set Date to the last millisecond of the month, just before midnight.
  7. Set date to clear the time values
  8. Set date to the end of the day
  9. Set Date to the start of the day
  10. Set date to the end of a day
  11. Set date to the start of an hour
  12. Set date to then end of an hour
  13. Set date to the start of a minute
  14. Set date to the end of a minute
  15. Set Calendar to Mid night
  16. Set year, month and day to a date
  17. Roll java.util.Date back and forth