Example usage for java.util Calendar add

List of usage examples for java.util Calendar add

Introduction

In this page you can find the example usage for java.util Calendar add.

Prototype

public abstract void add(int field, int amount);

Source Link

Document

Adds or subtracts the specified amount of time to the given calendar field, based on the calendar's rules.

Usage

From source file:gov.nih.nci.ncicb.tcga.dcc.qclive.common.util.DateUtils.java

/**
 * Return the next day from the given day (the next day at 00:00)
 *
 * @param day the day to calculate the next day for
 * @return the next day from the given day
 *///from  w w  w .  jav a2s.com
public static Calendar getNextDayFrom(final Calendar day) {

    day.set(Calendar.HOUR_OF_DAY, 0);
    day.set(Calendar.MINUTE, 0);
    day.set(Calendar.SECOND, 0);
    day.set(Calendar.MILLISECOND, 0);

    // Next day
    day.add(Calendar.DAY_OF_YEAR, 1);

    return day;
}

From source file:com.jdom.junit.utils.AbstractFixture.java

/**
 * Get a randomized value./*  w  w  w  .j a v  a 2 s.  c o  m*/
 * 
 * @param value
 *            the value to randomize
 * @param salt
 *            the randomizer to use
 * @return the randomized value
 */
public static Date getSaltedValue(Date value, int salt) {
    Date retValue;

    if (salt == 0) {
        retValue = value;
    } else {
        Calendar cal = Calendar.getInstance();
        cal.setTime(value);
        cal.add(Calendar.HOUR, salt);
        retValue = cal.getTime();
    }

    return retValue;
}

From source file:com.swiftcorp.portal.common.util.CalendarUtils.java

public static Calendar addDayToCurrentDate(int day) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(new Date());
    calendar.add(Calendar.DAY_OF_MONTH, day);

    return calendar;
}

From source file:Main.java

public static String previosTimeDate(int sub) {
    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
    java.util.Calendar calendar = java.util.Calendar.getInstance();
    java.util.Date date = null;/*from www  .  j  a  v a2s . c  o  m*/
    try {
        //date = simpleDateFormat.parse(simpleDateFormat.format(new Date())); 
        java.util.Date currentTime = calendar.getTime();

        calendar.setTime(currentTime);

        // add(Calendar.DAY_OF_MONTH, -5).
        calendar.add(java.util.Calendar.HOUR_OF_DAY, -sub);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return simpleDateFormat.format(calendar.getTime());

}

From source file:Main.java

/**
 * Creates a calendar object with the next absolute time determined by hour and minute
 * @param hourOfDay/*  ww w  . j a v  a 2 s .  c  om*/
 * @param minute
 * @return
 */
public static Calendar getNextAlarmTimeAbsolute(int hourOfDay, int minute) {
    Calendar cal = Calendar.getInstance();
    Calendar calNow = (Calendar) cal.clone();

    cal.set(Calendar.HOUR_OF_DAY, hourOfDay);
    cal.set(Calendar.MINUTE, minute);
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);

    if (cal.compareTo(calNow) <= 0) {
        //Today's time passed, count to tomorrow
        cal.add(Calendar.DATE, 1);
    }
    return cal;
}

From source file:com.uber.hoodie.common.model.HoodieTestUtils.java

public static List<String> monotonicIncreasingCommitTimestamps(int numTimestamps, int startSecsDelta) {
    Calendar cal = Calendar.getInstance();
    cal.add(Calendar.SECOND, startSecsDelta);
    List<String> commits = new ArrayList<>();
    for (int i = 0; i < numTimestamps; i++) {
        commits.add(HoodieActiveTimeline.COMMIT_FORMATTER.format(cal.getTime()));
        cal.add(Calendar.SECOND, 1);
    }/* w w  w .j a va 2 s .  c  om*/
    return commits;
}

From source file:gov.nih.nci.cabig.caaers.utils.DateUtils.java

/**
 * This is a convenient method to get yesterday date
 * @return/* www . j  a v a  2  s  .  c om*/
 */
public static Date yesterday() {
    Calendar c = Calendar.getInstance();
    c.add(Calendar.DATE, -1);
    Date d = c.getTime();
    d.setHours(0);
    d.setMinutes(0);
    return d;
}

From source file:com.project.framework.util.DateUtils.java

/**
 * ????//from  w w w.  j  a  v a  2  s.c  o m
 * @param date
 * @param second
 * @return date
 * @authorJiaYunqi
 */
public static Date getAddSecond(Date date, int second) {
    Calendar calendar = Calendar.getInstance();
    if (date != null) {
        calendar.setTime(date);
    }
    calendar.add(Calendar.SECOND, second);
    return calendar.getTime();
}

From source file:com.sungtech.goodTeacher.action.TeacherInfoAction.java

private static Date getNextDay(Date date) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(date);//from  w w  w.j  ava 2 s.c o  m
    calendar.add(Calendar.DAY_OF_MONTH, -1);
    date = calendar.getTime();
    return date;
}

From source file:gov.nih.nci.cabig.caaers.utils.DateUtils.java

/**
 * This is a convenient method to get tomorrow
 * @return//from  ww w. j ava  2  s .  com
 */
public static Date tomorrow() {
    Calendar c = Calendar.getInstance();
    c.add(Calendar.DATE, 1);

    Date d = c.getTime();
    d.setHours(0);
    d.setMinutes(0);

    return d;
}