Java Time Add addTime(Date aDate, int timeToAdd, int timeUnits)

Here you can find the source of addTime(Date aDate, int timeToAdd, int timeUnits)

Description

add Time

License

Apache License

Declaration

public static Date addTime(Date aDate, int timeToAdd, int timeUnits) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

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

public class Main {
    private Calendar calendar;
    private static final String COLON = ":";
    private static final String ZERO = "0";

    public static Date addTime(Date aDate, int timeToAdd, int timeUnits) {
        Calendar cal = GregorianCalendar.getInstance();
        cal.setTime(aDate);//from www  .  ja  va 2  s  .  com
        cal.add(timeUnits, timeToAdd);
        return cal.getTime();
    }

    public String getTime() {
        return getHour() + COLON + getMinute();
    }

    public int getHour() {
        return calendar.get(Calendar.HOUR_OF_DAY);
    }

    public String getMinute() {
        int tempMinute = calendar.get(Calendar.MINUTE);
        return tempMinute < 10 ? ZERO + tempMinute : Integer.toString(tempMinute);
    }
}

Related

  1. addTime(Date aDate, int timeToAdd, int timeUnits)
  2. addTime(Date baseDate, int amount, int datePart)
  3. addTime(Date current, Date toadd)
  4. addTime(Date date, Date addTime)