FastFoodCoding

Login


Connect with one of the following accounts





Login

Please wait while we redirect...

Views: 104 Ask New Question


How to add given number of hours to Date Object in Java?

On By


1 Answer


Following program shows you how to increment a Date Object by given Hours


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

public class AddHoursToDateObject {

    public static void main(String[] args) {

        Date input = new Date();
        int hoursToAdd = 10;

        Calendar cal = Calendar.getInstance();
        cal.setTime(input);
        cal.add(Calendar.HOUR_OF_DAY, hoursToAdd);
        Date output = cal.getTime();

        System.out.println(output);

    }
}
On By


Answer This Question


Top Tutorials

Top Questions

Top Articles

Top Blogs

Top News