Java Time Different getDiffDateTime(int diff)

Here you can find the source of getDiffDateTime(int diff)

Description

get Diff Date Time

License

Apache License

Declaration

public static final Date getDiffDateTime(int diff) 

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 Date getDiffDateTime(int diff) {
        Calendar c = Calendar.getInstance();

        c.setTime(new Date());
        c.add(Calendar.DATE, diff);
        return c.getTime();
    }/*from  w  w  w  . ja va 2 s  . co  m*/

    public static final String getDiffDateTime(int diff, int hours) {
        Calendar c = Calendar.getInstance();

        c.setTime(new Date());
        c.add(Calendar.DATE, diff);
        c.add(Calendar.HOUR, hours);
        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. calculateExecutionTimeDiff(String startDate, String endDate)
  2. createDate(String strDate, int[] timeDiff, boolean plusDiff)
  3. diffTime(String sTime, String fTime, String Dateformat1)
  4. getDifferent(final Date timeFrom, final Date timeTo)
  5. getDiffTime(Date beforeTime, Date afterTime)
  6. getDiffTime(long startTime)
  7. getDiffTime(String strDate, int idx)