Java Date Previous getPreviousMonth(long date)

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

Description

Returns the previous month.

License

Open Source License

Parameter

Parameter Description
date Base date

Return

previous month

Declaration

public static long getPreviousMonth(long date) 

Method Source Code


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

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

    /**//from  ww  w.j a va 2 s.c  om
     * Returns the previous month.
     *
     * @param date Base date
     * @return previous month
     */
    public static long getPreviousMonth(long date) {
        return incrementMonth(date, -1);
    }

    private static long incrementMonth(long date, int increment) {
        Calendar calendar = CALENDAR;
        synchronized (calendar) {
            calendar.setTimeInMillis(date);
            calendar.add(Calendar.MONTH, increment);
            return calendar.getTimeInMillis();
        }
    }
}

Related

  1. getPreviousDay(Date dateTime)
  2. getPreviousDay(Date inputDate)
  3. getPreviousFriday(final Date d)
  4. getPreviousMonday(Date day)
  5. getPreviousMonth(Date time)
  6. getPreviousMonthFirst(Date appointDate)
  7. getPreviousQuarterStartDate(Date dt)
  8. getPreviuosRoundMonth(Date baseDate)
  9. previousDay(Date date)