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 getTomorrowAt(int hours, int minutes) {
    Calendar today = Calendar.getInstance();
    Calendar cal = Calendar.getInstance();
    cal.clear();//from  w  ww  .j  a  v  a  2s  .c o  m

    int year = today.get(Calendar.YEAR);
    int month = today.get(Calendar.MONTH);
    //represents the day of the month
    today.add(Calendar.DATE, 1);
    int day = today.get(Calendar.DATE);
    cal.set(year, month, day, hours, minutes, 0);
    return cal;
}

From source file:com.sanyanyu.syybi.utils.DateUtils.java

public static String getOffsetMonth(int offset, String pattern) {
    Calendar cal = Calendar.getInstance();
    cal.add(Calendar.MONTH, offset);
    String currentDate = DateFormatUtils.format(cal, pattern);
    return currentDate;
}

From source file:Main.java

public static long endOfThisMonth() {
    Calendar cal = Calendar.getInstance();
    cal.set(Calendar.DAY_OF_MONTH, 1);
    cal.set(Calendar.HOUR_OF_DAY, 23);
    cal.set(Calendar.MINUTE, 59);
    cal.set(Calendar.SECOND, 59);
    cal.set(Calendar.MILLISECOND, 999);
    cal.add(Calendar.MONTH, 1);
    cal.add(Calendar.DATE, -1);//w ww  .j av a  2 s  .  com
    Date date = cal.getTime();
    return date.getTime();
}

From source file:com.sanyanyu.syybi.utils.DateUtils.java

/** 
  * @Title:getOffsetDate /*  w  w w. j  av  a2s.  c om*/
  * @Description: ????X 
  * @param offset 
  * @return 
  * @return String 
  */
public static String getOffsetDate(int offset) {
    Calendar cal = Calendar.getInstance();
    cal.add(Calendar.DAY_OF_MONTH, offset);
    String currentDate = DateFormatUtils.format(cal, "yyyy-MM-dd");
    return currentDate;
}

From source file:Main.java

@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
private static void generateNewKeyOld(Context context) {
    try {/*w w  w.ja  v a 2 s  .  c  o  m*/
        KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance(KeyProperties.KEY_ALGORITHM_RSA,
                KEY_PROVIDER);

        Calendar instance = Calendar.getInstance();
        Date start = instance.getTime();

        instance.add(Calendar.YEAR, 1);
        Date end = instance.getTime();

        keyPairGenerator.initialize(new KeyPairGeneratorSpec.Builder(context).setAlias(KEY_ALIAS)
                .setSubject(new X500Principal("CN=" + KEY_ALIAS)).setSerialNumber(BigInteger.valueOf(20151021))
                .setStartDate(start).setEndDate(end).build());

        keyPairGenerator.generateKeyPair();

    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
    } catch (NoSuchProviderException e) {
        e.printStackTrace();
    } catch (InvalidAlgorithmParameterException e) {
        e.printStackTrace();
    }
}

From source file:Main.java

/**
 * Returns Date object of the next day of d.
 * @return/*from   ww  w.j a  v  a  2 s .  c o  m*/
 */
public static Date getNextDay(Date d) {
    Calendar c = Calendar.getInstance();
    if (d != null)
        c.setTime(d);
    c.set(Calendar.HOUR_OF_DAY, 0);
    c.set(Calendar.MINUTE, 0);
    c.set(Calendar.SECOND, 0);
    c.set(Calendar.MILLISECOND, 0);
    c.add(Calendar.DAY_OF_MONTH, 1);
    return c.getTime();
}

From source file:jp.co.opentone.bsol.framework.core.util.DateUtil.java

/**
 * ?????????.//  www.  jav  a  2 s. c  o m
 * @param deadline ?
 * @return true:?
 */
public static boolean isExpire(Date deadline) {
    if (deadline == null) {
        return false;
    }
    // ?+1?
    Calendar cal = Calendar.getInstance();
    cal.setTime(deadline);
    cal.add(Calendar.DATE, 1);
    return cal.getTime().before(getNow());
}

From source file:com.wavemaker.runtime.FileController.java

public static void setCacheExpireDate(HttpServletResponse response, int seconds) {
    if (response != null) {
        Calendar cal = new GregorianCalendar();
        cal.add(Calendar.SECOND, seconds);
        response.setHeader("Cache-Control", "PUBLIC, max-age=" + seconds + ", must-revalidate");
        response.setHeader("Expires", htmlExpiresDateFormat().format(cal.getTime()));
    }//from www . j  a v  a 2 s.  c  om
}

From source file:Main.java

public static long getPeriodEnd(int periodType, long date) {
    final Calendar cal = Calendar.getInstance();
    cal.setTimeInMillis(getPeriodStart(periodType, date));

    switch (periodType) {
    case TYPE_DAY: {
        cal.add(Calendar.DAY_OF_YEAR, 1);
        break;/* w ww. j  av a2s .  c  o  m*/
    }

    case TYPE_WEEK: {
        cal.add(Calendar.WEEK_OF_YEAR, 1);
        break;
    }

    case TYPE_MONTH: {
        cal.add(Calendar.MONTH, 1);
        break;
    }

    case TYPE_YEAR: {
        cal.add(Calendar.YEAR, 1);
        break;
    }
    }

    cal.add(Calendar.MILLISECOND, -1);
    return cal.getTimeInMillis();
}

From source file:Main.java

public static int[] getSchoolCalDate(int year, int month, int day, int week, int dayOfWeek) {
    Calendar cal = Calendar.getInstance();
    cal.set(year, month - 1, day);/*from   w  ww. ja  v a2 s  .c om*/
    Log.d(TAG, "Date: " + cal.toString());
    Log.d(TAG, "year: " + year);
    Log.d(TAG, "month: " + month);
    Log.d(TAG, "day: " + day);
    cal.add(Calendar.DATE, -offset(cal.get(Calendar.DAY_OF_WEEK)));
    int count = (week - 1) * 7 + dayOfWeek - 1;
    Log.d(TAG, "count: " + count);
    cal.add(Calendar.DATE, count);
    int result[] = { cal.get(Calendar.YEAR), cal.get(Calendar.MONTH) + 1, cal.get(Calendar.DAY_OF_MONTH) };

    return result;
}