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 List<String> getOldWeekDays() {
    final Calendar c = Calendar.getInstance();
    String[] months = new String[8];
    for (int i = 0; i < 8; i++) {
        months[i] = new SimpleDateFormat("MM.dd").format(new Date(c.getTimeInMillis()));
        c.add(Calendar.DAY_OF_MONTH, -1);
    }/*from   www  .  j a  v a 2s  . com*/
    return Arrays.asList(months);
}

From source file:Main.java

public static Calendar GetTodayLeftRange(Calendar today) {
    Calendar calendar = (Calendar) today.clone();
    calendar.set(Calendar.HOUR_OF_DAY, 0);
    calendar.set(Calendar.MINUTE, 0);
    calendar.set(Calendar.SECOND, 0);
    calendar.set(Calendar.MILLISECOND, 0);
    calendar.add(Calendar.MINUTE, 0);
    return calendar;
}

From source file:Main.java

public static Calendar tomorrow() {
    Calendar tomorrow = new GregorianCalendar();
    tomorrow.set(Calendar.HOUR_OF_DAY, 0);
    tomorrow.set(Calendar.MINUTE, 0);
    tomorrow.set(Calendar.SECOND, 0);
    tomorrow.set(Calendar.MILLISECOND, 0);
    tomorrow.add(Calendar.DAY_OF_MONTH, 1);
    return tomorrow;
}

From source file:com.mediaportal.ampdroid.api.JsonUtils.java

public static BasicNameValuePair newPair(String _name, Date _value) {
    Calendar cal = Calendar.getInstance();
    cal.setTime(_value);/*from  ww w  . ja  v  a  2s.c om*/
    int offset = (int) ((cal.get(Calendar.ZONE_OFFSET) + cal.get(Calendar.DST_OFFSET)) / 60000);

    cal.add(Calendar.MINUTE, offset);
    String dateString = IsoDate.dateToString(cal.getTime(), IsoDate.DATE_TIME);

    return new BasicNameValuePair(_name, dateString);
}

From source file:Main.java

public static Calendar GetYesterdayLeftRange(Calendar today) {
    Calendar calendar = (Calendar) today.clone();
    calendar.set(Calendar.HOUR_OF_DAY, 0);
    calendar.set(Calendar.MINUTE, 0);
    calendar.set(Calendar.SECOND, 0);
    calendar.set(Calendar.MILLISECOND, 0);
    calendar.add(Calendar.DAY_OF_MONTH, -1);
    calendar.add(Calendar.MINUTE, 0);
    return calendar;
}

From source file:Main.java

public static Calendar GetTodayRightRange(Calendar today) {
    Calendar calendar = (Calendar) today.clone();
    calendar.set(Calendar.HOUR_OF_DAY, 23);
    calendar.set(Calendar.MINUTE, 59);
    calendar.set(Calendar.SECOND, 0);
    calendar.set(Calendar.MILLISECOND, 0);
    calendar.add(Calendar.MINUTE, 0);
    return calendar;
}

From source file:Main.java

public static Calendar GetYesterdayRightRange(Calendar today) {
    Calendar calendar = (Calendar) today.clone();
    calendar.set(Calendar.HOUR_OF_DAY, 23);
    calendar.set(Calendar.MINUTE, 59);
    calendar.set(Calendar.SECOND, 0);
    calendar.set(Calendar.MILLISECOND, 0);
    calendar.add(Calendar.DAY_OF_MONTH, -1);
    calendar.add(Calendar.MINUTE, 0);
    return calendar;
}

From source file:com.qdum.llhb.common.utils.DateUtils.java

/**
 * getMonthFirstDay??:??//from   w ww  . j av  a  2 s. c o  m
 *
 * @author yaoyt
 * @time 15/12/29 ?1:19
 */
public static Date getMonthFirstDay() {
    Calendar c = Calendar.getInstance();
    c.add(Calendar.MONTH, 0);
    c.set(Calendar.DAY_OF_MONTH, 1);//1?,?
    return c.getTime();
}

From source file:Main.java

/**
 * Add the given number of days to the calendar and convert to Date.
 *
 * @param calendar/*ww  w  .  j av  a 2s. c o  m*/
 *            The calendar to add to.
 * @param days
 *            The number of days to add.
 * @return The date object given by the modified calendar.
 */
private static Date rollGetDate(Calendar calendar, int days) {
    Calendar easterSunday = (Calendar) calendar.clone();
    easterSunday.add(Calendar.DATE, days);
    return easterSunday.getTime();
}

From source file:com.redhat.rhn.domain.common.CommonFactory.java

/**
 * Create a TinyUrl/*  w ww  .  ja  v  a2 s.co  m*/
 * @param urlIn to tinyfy
 * @param expires the date we *ADD* 6 hours to to set the expiration on the URL
 * @return TinyUrl instance
 */
public static TinyUrl createTinyUrl(String urlIn, Date expires) {
    String token = RandomStringUtils.randomAlphanumeric(8);
    TinyUrl existing = lookupTinyUrl(token);
    while (existing != null) {
        log.warn("Had collision with: " + token);
        token = RandomStringUtils.randomAlphanumeric(8);
        existing = lookupTinyUrl(token);
    }

    TinyUrl url = new TinyUrl();
    Config c = new Config();
    url.setUrl(urlIn);
    url.setEnabled(true);
    url.setToken(token);
    Calendar pcal = Calendar.getInstance();
    pcal.setTime(expires);
    pcal.add(Calendar.HOUR, c.getInt("server.satellite.tiny_url_timeout", 4));
    url.setExpires(new Date(pcal.getTimeInMillis()));
    return url;
}