Java Date Difference getDiffMon(Date dt, int idiff)

Here you can find the source of getDiffMon(Date dt, int idiff)

Description

get Diff Mon

License

Apache License

Declaration

public static final String getDiffMon(Date dt, int idiff) 

Method Source Code


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

import java.text.DateFormat;

import java.text.SimpleDateFormat;

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

public class Main {
    public static final String dtSimple = "yyyy-MM-dd";

    public static final String getDiffMon(Date dt, int idiff) {
        Calendar c = Calendar.getInstance();
        c.setTime(dt);//from w  w w  .  j  a v a2  s . c o m
        c.add(Calendar.MONTH, idiff);
        return dtSimpleFormat(c.getTime());
    }

    /**
     * yyyy-MM-dd
     * 
     * @param date
     * 
     * @return
     */
    public static final String dtSimpleFormat(Date date) {
        if (date == null) {
            return "";
        }

        return getFormat(dtSimple).format(date);
    }

    private static final DateFormat getFormat(String format) {
        return new SimpleDateFormat(format);
    }
}

Related

  1. getDiffDays2(Date one, Date two)
  2. getDifference(Date a, Date b)
  3. getDifference(String dateStr1, String dateStr2, char choice)
  4. getDifferenceInDays(Calendar calendar0, Calendar calendar1)
  5. getDiffMon(Date dt, int idiff)
  6. getDiffToString(Date date, int n, String pattern)
  7. getScoreDifferenceString(int newNumber, int oldNumber)
  8. getSecondDiff(Date d1, Date d2)
  9. getTimeDifferenceInSeconds(Date d, Date d2)