Java Time Add addTime(Date date, Date addTime)

Here you can find the source of addTime(Date date, Date addTime)

Description

add Time

License

Open Source License

Declaration

public static Date addTime(Date date, Date addTime) 

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 Date addTime(Date date, Date addTime) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(addTime);/*from   ww  w. j  av  a2s  . c om*/

        int addHour = calendar.get(Calendar.HOUR);
        int addMinute = calendar.get(Calendar.MINUTE);
        int addSecond = calendar.get(Calendar.SECOND);
        int addMillisecond = calendar.get(Calendar.MILLISECOND);

        calendar.setTime(date);

        calendar.add(Calendar.MILLISECOND, addMillisecond);
        calendar.add(Calendar.SECOND, addSecond);
        calendar.add(Calendar.MINUTE, addMinute);
        calendar.add(Calendar.HOUR, addHour);

        return calendar.getTime();
    }
}

Related

  1. addTime(Date aDate, int timeToAdd, int timeUnits)
  2. addTime(Date aDate, int timeToAdd, int timeUnits)
  3. addTime(Date baseDate, int amount, int datePart)
  4. addTime(Date current, Date toadd)
  5. addTime(Date date, int field, int value)
  6. addTime(Date date, int field, int value)
  7. addTime(Date date, int mode, int amount)
  8. addTime(Date date, String time)