get Day After Date - Java java.util

Java examples for java.util:Day

Description

get Day After Date

Demo Code


//package com.java2s;

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

public class Main {
    public static void main(String[] argv) throws Exception {
        Date date = new Date();
        int days = 2;
        System.out.println(getDayAfterDate(date, days));
    }//from   ww  w  .  java2  s  .c  om

    static public Date getDayAfterDate(Date date, int days) {
        Calendar calendarD = Calendar.getInstance();
        calendarD.setTime(date);
        calendarD.set(Calendar.DATE, calendarD.get(Calendar.DATE) + days);
        return calendarD.getTime();

    }

    static public Date getTime(int hour, int min, int sec) {
        Calendar calendar = Calendar.getInstance();
        calendar.set(Calendar.HOUR_OF_DAY, hour);
        calendar.set(Calendar.MINUTE, min);
        calendar.set(Calendar.SECOND, sec);
        return calendar.getTime();
    }
}

Related Tutorials