Java Date Previous getPreviousDate(int period)

Here you can find the source of getPreviousDate(int period)

Description

get Previous Date

License

Open Source License

Declaration

public static Date getPreviousDate(int period) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

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

public class Main {

    public static Date getPreviousDate(int period) {
        Date today = new Date();
        Calendar calendar = new GregorianCalendar();
        calendar.setTime(today);//from www.  j  a va 2 s  . c  o m

        if (period == 7) {
            calendar.add(Calendar.DATE, -7);
        } else if (period == 30) {
            calendar.add(Calendar.MONTH, -1);
        } else {
            calendar.add(Calendar.YEAR, -1);
        }
        return calendar.getTime();
    }
}

Related

  1. getPreMonthDate(Date date, int month)
  2. getPrevDay(Date date)
  3. getPrevDueDate(int payperiod, long time)
  4. getPreviousDate(Date date)
  5. getPreviousDate(final Date date)
  6. getPreviousDateStart()
  7. getPreviousDay(Date date)
  8. getPreviousDay(Date dateTime)
  9. getPreviousDay(Date inputDate)