Java Hour Calculate getDiffDateTime(int diff, int hours)

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

Description

get Diff Date Time

License

Open Source License

Declaration

public static final String getDiffDateTime(int diff, int hours) 

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

        c.setTime(new Date());
        c.add(Calendar.DATE, diff);
        return c.getTime();
    }// www  . j  a  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 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. diffHour(String day1, String day2)
  2. getBothTime(String startTime, int hours)
  3. getCurrHourDate()
  4. getDelayEndTime(int hour, String timezone)
  5. getDelayTime(int hour, String date)
  6. getDiffHour(String startTime, String endTime)
  7. getDoubleValue(String hours)
  8. getExpiresDate(int hours)
  9. getTime(String dateStr, int hour, String timeZone)