Java Time Add addTime(Date date, int mode, int amount)

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

Description

add Time

License

Open Source License

Declaration

protected static Date addTime(Date date, int mode, int amount) 

Method Source Code

//package com.java2s;

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

public class Main {

    protected static Date addTime(Date date, int mode, int amount) {
        Calendar cal = Calendar.getInstance();
        if (date != null)
            cal.setTime(date);/*from   ww  w .j ava  2 s  . c o  m*/
        cal.add(mode, amount);
        return cal.getTime();
    }

    private static Calendar setTime(final Calendar calendat, final String[] test) {
        if (test.length == 3) {
            calendat.set(Calendar.HOUR_OF_DAY, Integer.parseInt(test[0].trim()));
            calendat.set(Calendar.MINUTE, Integer.parseInt(test[1].trim()));
            calendat.set(Calendar.SECOND, Integer.parseInt(test[2].trim()));
        }
        if (test.length == 2) {
            calendat.set(Calendar.HOUR_OF_DAY, Integer.parseInt(test[0].trim()));
            calendat.set(Calendar.MINUTE, Integer.parseInt(test[1].trim()));
            calendat.set(Calendar.SECOND, 0);
        }
        return calendat;
    }
}

Related

  1. addTime(Date baseDate, int amount, int datePart)
  2. addTime(Date current, Date toadd)
  3. addTime(Date date, Date addTime)
  4. addTime(Date date, int field, int value)
  5. addTime(Date date, int field, int value)
  6. addTime(Date date, String time)
  7. addTime(Date source, int hours, int minutes, int second)
  8. addTimeByDate(int dateNum, Date date)
  9. addTimeIntervals(Date date, int type, int num)