Set Date to Noon


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

public class Main {
  public static Date getNoonOfDay(Date day, Calendar cal) {
      if (day == null) day = new Date();
      cal.setTime(day);
      cal.set(Calendar.HOUR_OF_DAY, 12);
      cal.set(Calendar.MINUTE,      cal.getMinimum(Calendar.MINUTE));
      cal.set(Calendar.SECOND,      cal.getMinimum(Calendar.SECOND));
      cal.set(Calendar.MILLISECOND, cal.getMinimum(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