Java Calendar Day getNoonOfDay(Date day, Calendar cal)

Here you can find the source of getNoonOfDay(Date day, Calendar cal)

Description

Returns a Date set just to Noon, to the closest possible millisecond of the day.

License

Apache License

Declaration

public static Date getNoonOfDay(Date day, Calendar cal) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

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

public class Main {
    /**//  ww  w  .j  a  va2 s. c  o  m
     * Returns a Date set just to Noon, to the closest possible millisecond
     * of the day. If a null day is passed in, a new Date is created.
     * nnoon (00m 12h 00s)
     */
    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();
    }
}

Related

  1. getLastDayOfPreviousPeriod(int startDayOfPeriod, Calendar cal)
  2. getMonday(Calendar calendar)
  3. getNextDay(Calendar cal)
  4. getNextDay(Calendar calendar, int day)
  5. getNextMonday(Calendar date)
  6. getOneDayLaterCalendar(Date date)
  7. getPrincipalAfterCompoundingInterest( Calendar currentDate, Float principal, Integer depositPeriod, double interestPerDay, Integer compoundingInterval, Integer postingInterval)
  8. getRelativeCalendar(int offsetDays)
  9. getSafeTimeForAllDay(Calendar cal)