Java Date After getAfter(Date comparedDate, int cursor, String unit)

Here you can find the source of getAfter(Date comparedDate, int cursor, String unit)

Description

get After

License

Open Source License

Declaration

public static Date getAfter(Date comparedDate, int cursor, String unit) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

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

public class Main {
    public static String YEAR = "year";
    public static String MONTH = "month";
    public static String DAY = "day";
    public static String HOUR = "hour";
    public static String MINUTE = "minute";
    public static String SECOND = "second";

    public static Date getAfter(Date comparedDate, int cursor, String unit) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(comparedDate);//w  w  w.ja  v  a  2s .  co m
        int year = calendar.get(Calendar.YEAR);
        int month = calendar.get(Calendar.MONTH);
        int date = calendar.get(Calendar.DATE);
        int hour = calendar.get(Calendar.HOUR_OF_DAY);
        int minute = calendar.get(Calendar.MINUTE);
        int second = calendar.get(Calendar.SECOND);
        if (unit.equalsIgnoreCase(SECOND)) {
            second += cursor;
        } else if (unit.equalsIgnoreCase(MINUTE)) {
            minute += cursor;
        } else if (unit.equalsIgnoreCase(HOUR)) {
            hour += cursor;
        } else if (unit.equalsIgnoreCase(DAY)) {
            date += cursor;
        } else if (unit.equalsIgnoreCase(MONTH)) {
            month += cursor;
        } else if (unit.equalsIgnoreCase(YEAR)) {
            year += cursor;
        }
        calendar.set(year, month, date, hour, minute, second);
        return calendar.getTime();
    }
}

Related

  1. afterOneDay(Date depdt)
  2. dateAfter(Date date, int years, int months)
  3. dateAfter(Date origDate, int amount, int timeUnit)
  4. dateAfterNMonths(Date dt, int n)
  5. daysAfter(Date dateInst, int numDays)
  6. getAfterDay(Date date, int afterDays)
  7. getAfterDay(Date date, Integer day)
  8. getAfterDayNumber(Date endDate, Date startDate)
  9. getAfterEndDate(Integer day)