Java Date Calculate calculateNextSettleDate(Date date, int addMonth)

Here you can find the source of calculateNextSettleDate(Date date, int addMonth)

Description

calculate Next Settle Date

License

Open Source License

Declaration

public static Date calculateNextSettleDate(Date date, int addMonth) 

Method Source Code

//package com.java2s;

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

public class Main {

    public static Date calculateNextSettleDate(Date date, int addMonth) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);/*from  w ww .  jav  a  2s  . c o  m*/
        int dayOfMonth = calendar.get(Calendar.DAY_OF_MONTH);
        int maxOfMonth = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
        if (dayOfMonth == maxOfMonth) {
            calendar.add(Calendar.MONTH, addMonth);
            maxOfMonth = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
            calendar.set(Calendar.DAY_OF_MONTH, maxOfMonth);
        } else {
            calendar.add(Calendar.MONTH, addMonth);
        }
        return calendar.getTime();
    }

    public static Date add(Date when, int field, int amount) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(when);
        calendar.add(field, amount);
        return calendar.getTime();
    }
}

Related

  1. calculateDurationEndInSec(Date start, int durationInSeconds)
  2. calculateEndDate(Date startDate, int duration)
  3. calculateGestationAge(Date today, Date edd)
  4. calculateLookbackDate(int lookback)
  5. calculateMonthIn(Date date1, Date date2)
  6. calculateOffsetFromGMT(Date date)
  7. calculatePastDate(int days)
  8. calculateTime(Date date, String addpart, int num)
  9. calculateTime(Date sendTime, String timeZoneID)