Java Day Offset getOffsetDays(String strDate, String strDate2, String pFormat)

Here you can find the source of getOffsetDays(String strDate, String strDate2, String pFormat)

Description

get Offset Days

License

Open Source License

Declaration

public static int getOffsetDays(String strDate, String strDate2, String pFormat) throws Exception 

Method Source Code

//package com.java2s;
//License from project: GNU General Public License 

import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {

    public static int getOffsetDays(String strDate) throws Exception {

        SimpleDateFormat fmt = new SimpleDateFormat("yyyyMMdd");
        Date param_date = fmt.parse(strDate);

        return getOffsetDays(param_date, new Date());
    }/*from   www .  j av  a 2  s  .  com*/

    public static int getOffsetDays(Date pDate1, Date pDate2) throws Exception {

        return (int) ((pDate1.getTime() - pDate2.getTime()) / (1000 * 60 * 60 * 24));
    }

    public static int getOffsetDays(String strDate, String strDate2, String pFormat) throws Exception {

        SimpleDateFormat fmt = new SimpleDateFormat(pFormat);
        SimpleDateFormat fmt2 = new SimpleDateFormat(pFormat);

        Date param_date1 = fmt.parse(strDate);
        Date param_date2 = fmt2.parse(strDate2);

        return getOffsetDays(param_date1, param_date2);
    }

    public static int getOffsetDays(String strDate, String strDate2) throws Exception {

        return getOffsetDays(strDate, strDate2, "yyyyMMdd");
    }

    public static int getOffsetDays(int strDate, int strDate2) throws Exception {

        return getOffsetDays(Integer.toString(strDate), Integer.toString(strDate2), "yyyyMMdd");
    }
}

Related

  1. getOffsetDayOffNow(int offset)