Java Date Before getDateBeforeOrAfterV2(int idx)

Here you can find the source of getDateBeforeOrAfterV2(int idx)

Description

get Date Before Or After V

License

Apache License

Declaration

public static Date getDateBeforeOrAfterV2(int idx) 

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 {
    private final static String DATE_FORMAT = "yyyy-MM-dd";

    public static Date getDateBeforeOrAfterV2(int idx) {
        return getDateBeforeOrAfter(getFormatDateToDate(getCurrDate()), idx);
    }/*w  ww. j  av a 2 s. c om*/

    public static Date getDateBeforeOrAfter(int iDate) {
        Calendar cal = Calendar.getInstance();
        cal.add(Calendar.DAY_OF_MONTH, iDate);
        return cal.getTime();
    }

    public static Date getDateBeforeOrAfter(Date curDate, int iDate) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(curDate);
        cal.add(Calendar.DAY_OF_MONTH, iDate);
        return cal.getTime();
    }

    public static Date getFormatDateToDate(java.util.Date currDate) {
        return getFormatDate(getFormatDate(currDate));
    }

    public static java.util.Date getCurrDate() {
        return new java.util.Date();
    }

    public static String getFormatDate(java.util.Date currDate) {
        return getFormatDate(currDate, DATE_FORMAT);
    }

    public static Date getFormatDate(String currDate) {
        return getFormatDate(currDate, DATE_FORMAT);
    }

    public static String getFormatDate(java.util.Date currDate, String format) {
        SimpleDateFormat dtFormatdB = null;
        try {
            dtFormatdB = new SimpleDateFormat(format);
            return dtFormatdB.format(currDate);
        } catch (Exception e) {
            dtFormatdB = new SimpleDateFormat(DATE_FORMAT);
            try {
                return dtFormatdB.format(currDate);
            } catch (Exception ex) {
            }
        }
        return null;
    }

    public static Date getFormatDate(String currDate, String format) {
        SimpleDateFormat dtFormatdB = null;
        try {
            dtFormatdB = new SimpleDateFormat(format);
            return dtFormatdB.parse(currDate);
        } catch (Exception e) {
            dtFormatdB = new SimpleDateFormat(DATE_FORMAT);
            try {
                return dtFormatdB.parse(currDate);
            } catch (Exception ex) {
            }
        }
        return null;
    }
}

Related

  1. getDateBefore(int year, int month, int day)
  2. getDateBefore(String d, int day)
  3. getDateBeforeHours(Date date, int hours)
  4. getDateBeforeNextMonth(Date date, Integer month, Integer day)
  5. getDateBeforeOrAfter(int iDate)
  6. getDateBeforeSomeMinutes(int minute, long timestamp)
  7. getDateBeforeTheDay(String day, int num)
  8. getDateBeforeToday(int num)
  9. getDateBeforTwelveMonth()