Java Day of getBeforeDate(int day)

Here you can find the source of getBeforeDate(int day)

Description

get Before Date

License

Apache License

Declaration

public static Date getBeforeDate(int day) throws Exception 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class Main {

    public static Date getBeforeDate(int day) throws Exception {
        Calendar cl = Calendar.getInstance();
        Long clTemp = cl.getTimeInMillis() - day * 24 * 60 * 60 * 1000L;
        cl.setTimeInMillis(clTemp);//from  w  w w  . ja  v a  2s  .  c  om
        return getFormatDate(cl.getTime(), "yyyy-MM-dd");
    }

    public static Date getFormatDate(Date date, String format) throws Exception {
        String dateStr = getDate2String(date, format);
        return getString2Date(dateStr, format);
    }

    public static String getDate2String(Date date, String format) {
        SimpleDateFormat sformat = new SimpleDateFormat(format);
        return sformat.format(date);
    }

    public static Date getString2Date(String date, String format) throws Exception {
        SimpleDateFormat sformat = new SimpleDateFormat(format);
        return sformat.parse(date);
    }
}

Related

  1. get8BitTime(Date date, int deltaDay)
  2. getAfterDays(String date, String pattern, int afterDays)
  3. getAge(Date birthDay)
  4. getAgeOfCalendar(String birthDayString)
  5. getApisPaxBirthday(String dob)
  6. getBeforeOrAfterDay(Date date, String format, Integer days)
  7. getBeginEndTimeOfDay(Date day)
  8. getBeginOfDay(Date date)
  9. getBeginTimeOfDay(Date date, int offset)