Here you can find the source of getRelativeCalendar(int offsetDays)
Parameter | Description |
---|---|
offsetDays | the offset in day relative to today |
public static Calendar getRelativeCalendar(int offsetDays)
//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; } }