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:Main.java

public static Calendar getExpireTime(int expireSeconds) {
    Calendar c = Calendar.getInstance();
    c.add(Calendar.SECOND, expireSeconds);
    return c;//from w ww . j a v a2  s  .c o m
}

From source file:Main.java

public static Date getYesterdayDate() {
    Calendar cal = Calendar.getInstance();
    cal.add(Calendar.DATE, -1);
    return cal.getTime();
}

From source file:Main.java

public static Date getYesterday(Date from) {
    Calendar c = buildFromDate(from);
    c.add(Calendar.DATE, -1); // number of days to add
    return c.getTime();
}

From source file:Main.java

public static Calendar getMonthsByOffset(Calendar c, int offset) {
    Calendar nextC = (Calendar) c.clone();
    nextC.add(Calendar.MONTH, offset);
    return nextC;
}

From source file:Main.java

public static Date getTomorrow(Date from) {
    Calendar c = buildFromDate(from);
    c.add(Calendar.DATE, 1); // number of days to add
    return c.getTime();
}

From source file:Main.java

public static String getNextHourDateTime() {
    Calendar c = Calendar.getInstance();
    c.add(Calendar.HOUR, 1);
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:MM:ss");
    String nextTime = sdf.format(new Date(c.getTimeInMillis()));
    return nextTime;
}

From source file:Main.java

public static String getPreviousDate(int days) {
    Calendar cal = Calendar.getInstance();
    cal.add(Calendar.DATE, -days);
    return sdf.format(cal.getTime());
}

From source file:Main.java

public static String getNowTime() {
    Calendar nowTime = Calendar.getInstance();
    nowTime.add(Calendar.HOUR_OF_DAY, 8);
    return new SimpleDateFormat("yyyyMMddHHmmssSSS").format(nowTime.getTime());
}

From source file:Main.java

public static String getYesterdayData() {
    Calendar cal = Calendar.getInstance();
    cal.add(Calendar.DATE, -1);
    String yesterday = new SimpleDateFormat("yyyy-MM-dd ").format(cal.getTime());
    return yesterday;
}

From source file:Main.java

public static int getDayOfMonth(int offset) {
    Calendar calendar = Calendar.getInstance();
    calendar.add(Calendar.MONTH, offset);
    return calendar.get(Calendar.DAY_OF_MONTH);
}