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

Open Source License

Declaration

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

Method Source Code


//package com.java2s;

import java.text.DateFormat;

import java.text.SimpleDateFormat;
import java.util.*;

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

    public static final String getDiffMon(Date dt, int idiff) {
        Calendar c = Calendar.getInstance();
        c.setTime(dt);//  w  w  w .  ja v a  2 s.c om
        c.add(Calendar.MONTH, idiff);
        return dateFormat(c.getTime());
    }

    public static final String dateFormat(Date date) {
        if (date == null) {
            return "";
        }
        return getFormat(dateFormat).format(date);
    }

    public static final String format(Date date, String formate) {
        if (date == null) {
            return "";
        }
        return getFormat(formate).format(date);
    }

    public static final String format(Long dateTmie, String formate) {
        Date date = new Date(dateTmie);
        return getFormat(formate).format(date);
    }

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

Related

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