Java Day of Week previousWeek(long date)

Here you can find the source of previousWeek(long date)

Description

Returns the week before date.

License

Open Source License

Parameter

Parameter Description
date Date used in calculating previous week

Return

week before date.

Declaration

public static long previousWeek(long date) 

Method Source Code


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

public class Main {
    private static Calendar CALENDAR = Calendar.getInstance();

    /**//from w w w.j a  v  a  2  s. co m
     * Returns the week before <code>date</code>.
     *
     * @param date Date used in calculating previous week
     * @return week before <code>date</code>.
     */
    public static long previousWeek(long date) {
        return addDays(date, -7);
    }

    /**
     * Adds <code>amount</code> days to <code>time</code> and returns
     * the resulting time.
     *
     * @param time Base time
     * @param amount Amount of increment.
     *
     * @return the <var>time</var> + <var>amount</var> days
     */
    public static long addDays(long time, int amount) {
        Calendar calendar = CALENDAR;
        synchronized (calendar) {
            calendar.setTimeInMillis(time);
            calendar.add(Calendar.DAY_OF_MONTH, amount);
            return calendar.getTimeInMillis();
        }
    }
}

Related

  1. mergeDayIntoDate(Date baseDate, int dayOfWeek)
  2. nextDayOfWeek(Date fromDate, int dow)
  3. nextWeek(Date date)
  4. nextWeek(final Date date)
  5. previousWeek(long date)
  6. startOfWeek(Date date)
  7. toStartWeek(Date date)
  8. toWeekDayUS(Date date, int expect)
  9. truncDateToIsoWeek(Date d)