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:com.rmn.qa.AutomationUtils.java

/**
 * Modifies the specified date/*from w w  w  .j  av  a 2s  .co  m*/
 * @param dateToModify Date to modify
 * @param unitsToModify Number of units to modify (e.g. 6 for 6 seconds)
 * @param unitType Measurement type (e.g. Calendar.SECONDS)
 * @return Modified date
 */
public static Date modifyDate(Date dateToModify, int unitsToModify, int unitType) {
    Calendar c = Calendar.getInstance();
    c.setTime(dateToModify);
    // Add 60 seconds so we're as close to the hour as we can be instead of adding 55 again
    c.add(unitType, unitsToModify);
    return c.getTime();
}

From source file:net.kamhon.ieagle.util.DateUtil.java

public static Date addDate(Date date, int noOfDays) {
    Calendar cal = setTime(date);
    cal.add(Calendar.DATE, noOfDays);
    return cal.getTime();
}

From source file:Main.java

@NonNull
static Date convertDate(int date, int time) {
    Calendar calendar = Calendar.getInstance();
    calendar.set(Calendar.YEAR, 1997);
    calendar.set(Calendar.MONTH, Calendar.JANUARY);
    calendar.set(Calendar.DAY_OF_MONTH, 1);
    calendar.set(Calendar.HOUR_OF_DAY, time / 60);
    calendar.set(Calendar.MINUTE, time % 60);

    calendar.add(Calendar.DATE, date);

    return calendar.getTime();
}

From source file:Main.java

/**
 * Determines what year a transaction belongs to.
 * /*  w  w w .ja v a 2  s .  co  m*/
 * If the given <code>day</code> of the given <code>month</code> for the current year
 * is in the future the transaction is probably from last year.
 * 
 * @param month     The month, where January is 1.
 * @param day       The day of the month, starting from 1.
 * @return          An ISO 8601 formatted date.
 */
public static String getTransactionDate(int month, int day) {
    month--; // Java-months start at 0
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    Calendar cal = Calendar.getInstance();
    int currentYear = cal.get(Calendar.YEAR);
    cal.set(currentYear, month, day, 0, 0);
    if (cal.getTime().after(Calendar.getInstance().getTime())) {
        //If the transaction is in the future the year is probably of by +1.
        cal.add(Calendar.YEAR, -1);
    }
    return sdf.format(cal.getTime());
}

From source file:com.chess.genesis.net.GenesisNotifier.java

public static void ScheduleWakeup(final Context context) {
    final Calendar cal = Calendar.getInstance();
    cal.add(Calendar.MINUTE, Pref.getInt(context, R.array.pf_notifierPolling));
    final long start = cal.getTimeInMillis();
    final long interval = start - System.currentTimeMillis();

    final Intent intent = new Intent(context, GenesisAlarm.class);
    final PendingIntent pintent = PendingIntent.getBroadcast(context, 0, intent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    final AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    am.setInexactRepeating(AlarmManager.RTC, start, interval, pintent);
}

From source file:com.ykun.commons.utils.commons.DateUtils.java

/**
 * ??/*  w  w  w . ja va 2 s  .  c  o m*/
 *
 * @param date     
 * @param dateType 
 * @param amount   
 * @return ?
 */
private static Date addInteger(Date date, int dateType, int amount) {
    Date myDate = null;
    if (date != null) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.add(dateType, amount);
        myDate = calendar.getTime();
    }
    return myDate;
}

From source file:edu.umn.cs.sthadoop.operations.STJoin.java

private static String addtimeSpaceToInterval(String date, int interval) throws ParseException {
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    Calendar c = Calendar.getInstance();
    c.setTime(sdf.parse(date));//from w  ww. j a v  a  2s. c om
    c.add(Calendar.DATE, interval);
    date = sdf.format(c.getTime());
    return date;
}

From source file:Main.java

public static void setDateTime(long timeStamp, Calendar currentCalender, int i) {
    currentCalender.setTimeInMillis(timeStamp);
    currentCalender.set(Calendar.DATE, 1);
    currentCalender.set(Calendar.HOUR_OF_DAY, 0);
    currentCalender.set(Calendar.MINUTE, 0);
    currentCalender.set(Calendar.SECOND, 0);
    currentCalender.set(Calendar.MILLISECOND, 0);
    currentCalender.add(Calendar.DATE, i);
}

From source file:com.b5m.user.frame.util.DateUtils.java

public static Date getBeforeOrAfterDayToDate(Date date, int daycount) {
    Calendar calendar = null;
    if (daycount != 0) {
        calendar = Calendar.getInstance(); //
        calendar.setTime(date);//?
        calendar.add(Calendar.DAY_OF_MONTH, daycount); //  ? + dayCount
    }//  w  ww.j  a v  a  2  s  . c  o m
    return calendar.getTime();
}

From source file:com.wso2telco.gsma.authenticators.attributeshare.AbstractAttributeShare.java

public static void persistConsentedScopeDetails(AuthenticationContext context)
        throws DBUtilException, NamingException {

    AttributeConfigDao attributeConfigDao = new AttributeConfigDaoImpl();

    String msisdn = context.getProperty(Constants.MSISDN).toString();
    String operator = context.getProperty(Constants.OPERATOR).toString();
    String clientId = context.getProperty(Constants.CLIENT_ID).toString();

    List<SpConsent> spConsentDetailsList = attributeConfigDao.getScopeExpireTime(operator, clientId,
            context.getProperty(Constants.LONGLIVEDSCOPES).toString());
    List<UserConsentHistory> userConsentHistoryList = new ArrayList();

    for (SpConsent spConsent : spConsentDetailsList) {
        DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date today = new Date();

        Calendar calendar = Calendar.getInstance();
        calendar.setTime(today);/*from w ww  .  j  ava  2  s  .  com*/
        calendar.add(Calendar.DATE, spConsent.getExpPeriod());

        UserConsentHistory userConsentHistory = new UserConsentHistory();
        userConsentHistory.setMsisdn(msisdn);
        userConsentHistory.setConsentId(spConsent.getConsentId());
        userConsentHistory.setConsentExpireTime(dateFormat.format(calendar.getTime()));
        userConsentHistory.setConsentStatus(Constants.TRUE);
        userConsentHistory.setClientId(clientId);
        userConsentHistory.setOperatorName(operator);

        userConsentHistoryList.add(userConsentHistory);
    }
    attributeConfigDao.saveUserConsentedAttributes(userConsentHistoryList);
}