Java Calendar Day getRelativeCalendar(int offsetDays)

Here you can find the source of getRelativeCalendar(int offsetDays)

Description

Computes the day that has the given offset in days to today and returns it as an instance of Calendar .

License

Open Source License

Parameter

Parameter Description
offsetDays the offset in day relative to today

Return

a Calendar instance that is the begin of the day with the specified offset

Declaration

public static Calendar getRelativeCalendar(int offsetDays) 

Method Source Code


//package com.java2s;
import java.util.Calendar;

import java.util.GregorianCalendar;

public class Main {
    /**// w  w  w  .j ava2 s . c o  m
     * Computes the day that has the given offset in days to today
     * and returns it as an instance of {@code Calendar}.
     *
     * @param offsetDays   the offset in day relative to today
     * @return a {@code Calendar} instance that is the begin of the day
     *     with the specified offset
     */
    public static Calendar getRelativeCalendar(int offsetDays) {
        Calendar today = new GregorianCalendar();
        return getRelativeCalendar(today, offsetDays);
    }

    /**
     * Computes the day that has the given offset in days from the specified
     * <em>from</em> date and returns it as an instance of {@code Calendar}.
     *
     * @param from         the base date as {@code Calendar} instance
     * @param offsetDays   the offset in day relative to today
     * @return a {@code Calendar} instance that is the begin of the day
     *     with the specified offset from the given day
     */
    public static Calendar getRelativeCalendar(Calendar from, int offsetDays) {
        Calendar temp = new GregorianCalendar(from.get(Calendar.YEAR), from.get(Calendar.MONTH),
                from.get(Calendar.DATE), 0, 0, 0);
        temp.add(Calendar.DATE, offsetDays);
        return temp;
    }
}

Related

  1. getNextDay(Calendar calendar, int day)
  2. getNextMonday(Calendar date)
  3. getNoonOfDay(Date day, Calendar cal)
  4. getOneDayLaterCalendar(Date date)
  5. getPrincipalAfterCompoundingInterest( Calendar currentDate, Float principal, Integer depositPeriod, double interestPerDay, Integer compoundingInterval, Integer postingInterval)
  6. getSafeTimeForAllDay(Calendar cal)
  7. getStartAndEndOfDay(Calendar calendar)
  8. getStartOfDay(Calendar cal)
  9. getThatMonday(Calendar cal)