Example usage for java.util GregorianCalendar add

List of usage examples for java.util GregorianCalendar add

Introduction

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

Prototype

@Override
public void add(int field, int amount) 

Source Link

Document

Adds the specified (signed) amount of time to the given calendar field, based on the calendar's rules.

Usage

From source file:Main.java

/**
 * returns the string representation of the date X days ago
 * in the appropriate format for the URL
 * @param _numDaysAgo number of days before the current day
 * @return string representation of X days ago
 *//*w ww  . java 2  s.c om*/
public static String getUrlTimeStringForXDaysAgo(int _numDaysAgo) {
    GregorianCalendar cal = new GregorianCalendar();
    cal.add(Calendar.DAY_OF_MONTH, -1 * _numDaysAgo);
    return getUrlTimeString(cal);
}

From source file:Main.java

/**
 * CPLC dates are counted in days starting from "1986-02-04"
 * //from   w  w w.j a  v  a  2s. com
 * @param cplcDateValue
 * @return
 */
public static Calendar getDateFromCPLCDateValue(int cplcDateValue) {
    GregorianCalendar startDay = new GregorianCalendar(1977, 11, 29);
    startDay.add(Calendar.DAY_OF_YEAR, cplcDateValue);
    return startDay;
}

From source file:Main.java

/**
 *
 * @return/* w  ww  . j  a  v a 2 s  . c o m*/
 */
public static String tomorrow() {
    GregorianCalendar gc = new GregorianCalendar();
    gc.setTime(new Date());
    gc.add(GregorianCalendar.DATE, 1);
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

    return sdf.format(gc.getTime());
}

From source file:org.sonar.plugins.dbcleaner.period.Periods.java

static Date getDate(Configuration conf, String propertyKey, String defaultNumberOfMonths) {
    int months = conf.getInt(propertyKey, Integer.parseInt(defaultNumberOfMonths));
    GregorianCalendar calendar = new GregorianCalendar();
    calendar.add(GregorianCalendar.MONTH, -months);
    return calendar.getTime();
}

From source file:Spring.Repaso02.Principal.java

public static void demoPedido(PedidoDAO pedidodao, ProductoDAO productodao) {

    GregorianCalendar cal = inicializaCal();
    ArrayList<Producto> ALP = productodao.consultaAll(cal);
    Cliente c = crearClienteEjemplo();/*from w w  w  . j  a v a 2 s  . c om*/
    Pedido p = new Pedido();

    p.setIdCliente(c.getIdCliente());
    p.setFhPedido(cal);
    p.setIdPedido(1);
    p.setObservaciones("Prueba de pedido");

    if (cal.get(Calendar.HOUR_OF_DAY) <= 12) {
        p.setfRecogida(cal);
    } else {
        GregorianCalendar aux = cal;
        aux.add(Calendar.DATE, 1);
        p.setfRecogida(aux);
    }
    ArrayList<PedidoLinea> pl = new ArrayList();
    PedidoLinea aux;
    for (Producto producto : ALP) {
        aux = new PedidoLinea();
        aux.setProducto(producto);
        aux.setCantidad(2);
        pl.add(aux);
    }
    p.setLineasPedido(pl);
    pedidodao.baja(p);
    pedidodao.alta(p);
    System.out.println(pedidodao.consulta(p.getIdPedido()).toString());
    p.setObservaciones("Se ha modificado el pedido");
    pedidodao.modificacion(p);
    System.out.println(pedidodao.consulta(p.getIdPedido()).toString());
    System.out.println(pedidodao.consulta(c.getIdCliente(), cal).toString());
}

From source file:Main.java

private static Date calculate(Date d, int field, int amount) {
    if (d == null)
        return null;
    GregorianCalendar g = new GregorianCalendar();
    g.setGregorianChange(d);/*from  ww w.  j  a  va  2s .  c om*/
    g.add(field, amount);
    return g.getTime();
}

From source file:DateUtils.java

public static Date getLastWeek() {
    GregorianCalendar dayBeforeThisWeek = new GregorianCalendar();
    int dayFromMonday = (dayBeforeThisWeek.get(Calendar.DAY_OF_WEEK) + 7 - Calendar.MONDAY) % 7;
    dayBeforeThisWeek.add(Calendar.DATE, -dayFromMonday - 1);
    return dayBeforeThisWeek.getTime();
}

From source file:com.tdclighthouse.prototype.utils.TdcUtils.java

public static String getExpiresDate(int hours) {
    GregorianCalendar calendar = new GregorianCalendar();
    calendar.add(Calendar.HOUR, hours);
    Date date = calendar.getTime();
    return dateToRFC1123(date);

}

From source file:Main.java

public static long currentWeekInMills() {
    GregorianCalendar gregoriancalendar = new GregorianCalendar();
    GregorianCalendar gregoriancalendar1 = new GregorianCalendar(gregoriancalendar.get(1),
            gregoriancalendar.get(2), gregoriancalendar.get(5));
    gregoriancalendar1.setTimeZone(GMT);
    gregoriancalendar1.add(6, -(gregoriancalendar.get(7) - gregoriancalendar.getFirstDayOfWeek()));
    return gregoriancalendar1.getTimeInMillis();
}

From source file:org.apache.ranger.common.DateUtil.java

public static Date getLocalDateForUTCDate(Date date) {
    Calendar local = Calendar.getInstance();
    int offset = local.getTimeZone().getOffset(local.getTimeInMillis());
    GregorianCalendar utc = new GregorianCalendar();
    utc.setTimeInMillis(date.getTime());
    utc.add(Calendar.MILLISECOND, offset);
    return utc.getTime();
}