Example usage for java.util Calendar SECOND

List of usage examples for java.util Calendar SECOND

Introduction

In this page you can find the example usage for java.util Calendar SECOND.

Prototype

int SECOND

To view the source code for java.util Calendar SECOND.

Click Source Link

Document

Field number for get and set indicating the second within the minute.

Usage

From source file:sys.movil.manager.SolicitudServicioManager.java

public List<SolicitudServicioDto> obtener(SolicitudServicioDto dto) throws DAOException {
    String hql = "select e from SolicitudServicioDto e where e.id = e.id ";
    List<Object> listaParametros = new ArrayList<Object>();
    if (dto.getId() != null && !dto.getId().equals(0L)) {
        hql += " and e.id = ?";
        listaParametros.add(dto.getId());
    } else {//from  w ww .j  a va 2 s . co m
        dto.setId(null);
    }
    if (dto.getChoferExternoDto() != null && dto.getChoferExternoDto().getNombresCompletos().length() != 0
            && !dto.getChoferExternoDto().getNombresCompletos().equals("")) {
        hql += " and e.choferExternoDto.nombresCompletos like '%?%'";
        listaParametros.add(dto.getChoferExternoDto().getNombresCompletos().toUpperCase());
    }
    if (dto.getUsuarioExternoDto() != null && dto.getUsuarioExternoDto().getNombresCompletos().length() != 0
            && !dto.getUsuarioExternoDto().getNombresCompletos().equals("")) {
        hql += " and e.usuarioExternoDto.nombresCompletos like '%?%'";
        listaParametros.add(dto.getUsuarioExternoDto().getNombresCompletos().toUpperCase());
    }
    if (dto.getFechaInicio() != null && dto.getFechaFin() != null) {

        hql += " and dto.fecha between ? and ?";
        Calendar c = Calendar.getInstance();
        c.setTime(dto.getFechaInicio());
        c.set(Calendar.HOUR, 0);
        c.set(Calendar.MINUTE, 0);
        c.set(Calendar.SECOND, 0);
        listaParametros.add(c.getTime());
        c.setTime(dto.getFechaFin());
        c.set(Calendar.HOUR, 23);
        c.set(Calendar.MINUTE, 59);
        c.set(Calendar.SECOND, 59);
        listaParametros.add(c.getTime());
    }
    hql += " order by e.id desc";
    return springHibernateDao.ejecutarQuery(hql, listaParametros);
}

From source file:DateUtil.java

/**
 * Convert the time to the midnight of the currently set date.
 * The internal date is changed after this call.
 *
 * @return a reference to this DateUtil, for concatenation.
 *///from w w w .jav a 2s  .co m
public DateUtil toMidnight() {

    cal.set(Calendar.HOUR_OF_DAY, 0);
    cal.set(Calendar.MINUTE, 0);
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);

    return this;
}

From source file:hsa.awp.scire.controller.TestController.java

@Test
public void testCall() {

    Set<Class<? extends IProcedureLogic<?>>> types = new HashSet<Class<? extends IProcedureLogic<?>>>();
    types.add(LogicDummy.class);
    controller.setProcedureLogicTypeList(types);

    int interval = 500;
    controller.setTimerInterval(interval);

    Campaign camp = Campaign.getInstance(0L);

    Calendar endShow = Calendar.getInstance();
    endShow.roll(Calendar.YEAR, 1);

    camp.setStartShow(Calendar.getInstance());
    camp.setName("123");
    camp.setEndShow(endShow);//from   w ww  .j a va 2  s  . c o m
    campaignFacade.saveCampaign(camp);

    FifoProcedure p = FifoProcedure.getInstance(0L);
    Calendar startDate = Calendar.getInstance();
    startDate.add(Calendar.SECOND, 2);

    Calendar endDate = Calendar.getInstance();
    while (startDate.compareTo(endDate) >= 0) {
        endDate.add(Calendar.SECOND, 5);
    }

    p.setInterval(startDate, endDate);

    campaignFacade.saveFifoProcedure(p);

    camp.addProcedure(p);

    campaignFacade.updateCampaign(camp);

    controller.startTimer();

    int i = 0;
    boolean foundStarted = false;
    boolean foundTerminated = false;
    LogicDummy dummy = null;

    while (i++ < 300) {
        if (foundStarted) {
            if (controller.findActiveLogicByProcedure(p.getId()) == null) {
                foundTerminated = true;
                logger.info("found started procedure");
                break;
            }
        } else if (controller.findActiveLogicByProcedure(p.getId()) != null) {
            foundStarted = true;
            dummy = (LogicDummy) controller.findActiveLogicByProcedure(p.getId());
            logger.info("found terminated procedure");
        }

        try {
            Thread.sleep(100);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    assertTrue(foundStarted);
    assertTrue(foundTerminated);
    assertTrue(dummy.getAfterActiveCount() > 0);
    assertTrue(dummy.getBeforeActiveCount() > 0);
    assertTrue(dummy.getWhileActiveCount() > 0);

    controller.stopTimer();
}

From source file:com.ar.dev.tierra.api.dao.impl.FacturaDAOImpl.java

@Override
public List<Factura> getDiaryReserva() {
    Criteria criteria = getSession().createCriteria(Factura.class);
    Calendar calendar = Calendar.getInstance();
    calendar.set(Calendar.HOUR_OF_DAY, 0);
    calendar.set(Calendar.MINUTE, 0);
    calendar.set(Calendar.SECOND, 0);
    Date fromDate = calendar.getTime();
    calendar.set(Calendar.HOUR_OF_DAY, 23);
    calendar.set(Calendar.MINUTE, 59);
    calendar.set(Calendar.SECOND, 59);
    Date toDate = calendar.getTime();
    criteria.add(Restrictions.between("fechaCreacion", fromDate, toDate));
    criteria.addOrder(Order.desc("idFactura"));
    criteria.add(Restrictions//w w w. j  a  v a  2  s  . com
            .not(Restrictions.in("estado", new String[] { "INICIADO", "CONFIRMADO", "CANCELADO" })));
    criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
    List<Factura> list = criteria.list();
    return list;
}

From source file:com.sirma.itt.emf.time.ISO8601DateFormat.java

/**
 * Format date into ISO format.// ww  w. j av  a2  s  . c o  m
 * 
 * @param isoDate
 *            the date to format
 * @return the ISO formatted string
 */
public static String format(Date isoDate) {
    if (isoDate == null) {
        return null;
    }
    // Note: always serialise to Gregorian Calendar
    Calendar calendar = new GregorianCalendar();
    calendar.setTime(isoDate);

    StringBuilder formatted = new StringBuilder(28);
    padInt(formatted, calendar.get(Calendar.YEAR), 4);
    formatted.append('-');
    padInt(formatted, calendar.get(Calendar.MONTH) + 1, 2);
    formatted.append('-');
    padInt(formatted, calendar.get(Calendar.DAY_OF_MONTH), 2);
    formatted.append('T');
    padInt(formatted, calendar.get(Calendar.HOUR_OF_DAY), 2);
    formatted.append(':');
    padInt(formatted, calendar.get(Calendar.MINUTE), 2);
    formatted.append(':');
    padInt(formatted, calendar.get(Calendar.SECOND), 2);
    formatted.append('.');
    padInt(formatted, calendar.get(Calendar.MILLISECOND), 3);

    TimeZone tz = calendar.getTimeZone();
    int offset = tz.getOffset(calendar.getTimeInMillis());
    formatted.append(getTimeZonePadding(offset));

    return formatted.toString();
}

From source file:com.linuxbox.enkive.statistics.gathering.past.PastGatherer.java

protected void setEndDate(int grain) {
    Calendar end = Calendar.getInstance();
    end.set(Calendar.MILLISECOND, 0);
    end.set(Calendar.SECOND, 0);
    end.set(Calendar.MINUTE, 0);//from   ww w.j  av  a  2 s  .  co m
    if (grain == CONSOLIDATION_HOUR) {
        end.add(Calendar.HOUR_OF_DAY, -hrKeepTime);
    } else if (grain == CONSOLIDATION_DAY) {
        end.set(Calendar.HOUR_OF_DAY, 0);
        end.add(Calendar.DATE, -dayKeepTime);
    } else if (grain == CONSOLIDATION_WEEK) {
        end.set(Calendar.HOUR_OF_DAY, 0);
        while (end.get(Calendar.DAY_OF_WEEK) != Calendar.SUNDAY) {
            end.add(Calendar.DATE, -1);
        }
        end.add(Calendar.WEEK_OF_YEAR, -weekKeepTime);
    } else if (grain == CONSOLIDATION_MONTH) {
        end.set(Calendar.HOUR_OF_DAY, 0);
        end.set(Calendar.DAY_OF_MONTH, 1);
        end.add(Calendar.MONTH, -monthKeepTime);
    }
    this.endDate = end.getTime();
}

From source file:com.ar.dev.tierra.api.dao.impl.ChartDAOImpl.java

@Override
public List<Chart> getDineroVendedores(int idVendedor) {
    Calendar calendarInitial = Calendar.getInstance();
    Calendar calendarClosing = Calendar.getInstance();
    calendarInitial.set(Calendar.HOUR_OF_DAY, 0);
    calendarInitial.set(Calendar.MINUTE, 0);
    calendarInitial.set(Calendar.SECOND, 0);
    calendarInitial.set(Calendar.MILLISECOND, 0);
    Date fromDate = calendarInitial.getTime();
    calendarClosing.set(Calendar.HOUR_OF_DAY, 23);
    calendarClosing.set(Calendar.MINUTE, 59);
    calendarClosing.set(Calendar.SECOND, 59);
    calendarClosing.set(Calendar.MILLISECOND, 59);
    Date toDate = calendarClosing.getTime();
    int days = 0;
    List<Chart> chartVenta = new ArrayList<>();
    while (days <= 6) {
        Chart chart = new Chart();
        Criteria facturas = getSession().createCriteria(Factura.class);
        facturas.add(Restrictions.like("estado", "CONFIRMADO"));
        facturas.add(Restrictions.between("fechaCreacion", fromDate, toDate));
        Criteria vendedorFactura = facturas.createCriteria("idVendedor");
        vendedorFactura.add(Restrictions.eq("idUsuario", idVendedor));
        facturas.setProjection(Projections.sum("total"));
        BigDecimal counter = (BigDecimal) facturas.uniqueResult();
        if (counter != null) {
            chart.setValue(counter.intValue());
        } else {// w w  w .  j a v  a2  s.  c  o m
            chart.setValue(0);
        }
        chart.setDate(fromDate);
        chartVenta.add(chart);
        calendarInitial.add(Calendar.DAY_OF_MONTH, -1);
        fromDate = calendarInitial.getTime();
        calendarClosing.add(Calendar.DAY_OF_MONTH, -1);
        toDate = calendarClosing.getTime();
        days++;
    }
    return chartVenta;
}

From source file:com.autentia.intra.bean.holiday.HolidayBean.java

/**
 * List holidays. Order depends on Faces parameter sort.
 *
 * @return the list of all holidays sorted by requested criterion
 *//*from w  ww .  j a  v a  2 s . c o  m*/
public List<Holiday> getAll() {
    if (selectedYear != null) {
        Calendar calMin = Calendar.getInstance();
        calMin.setTime(selectedYear);
        calMin.set(Calendar.MONTH, calMin.getMinimum(Calendar.MONTH));
        calMin.set(Calendar.DAY_OF_MONTH, calMin.getMinimum(Calendar.DAY_OF_MONTH));
        calMin.set(Calendar.HOUR_OF_DAY, calMin.getMinimum(Calendar.HOUR_OF_DAY));
        calMin.set(Calendar.MINUTE, calMin.getMinimum(Calendar.MINUTE));
        calMin.set(Calendar.SECOND, calMin.getMinimum(Calendar.SECOND));
        calMin.set(Calendar.MILLISECOND, calMin.getMinimum(Calendar.MILLISECOND));

        Calendar calMax = Calendar.getInstance();
        calMax.setTime(selectedYear);
        calMax.set(Calendar.MONTH, calMax.getMaximum(Calendar.MONTH));
        calMax.set(Calendar.DAY_OF_MONTH, calMax.getMaximum(Calendar.DAY_OF_MONTH));
        calMax.set(Calendar.HOUR_OF_DAY, calMax.getMaximum(Calendar.HOUR_OF_DAY));
        calMax.set(Calendar.MINUTE, calMax.getMaximum(Calendar.MINUTE));
        calMax.set(Calendar.SECOND, calMax.getMaximum(Calendar.SECOND));
        calMax.set(Calendar.MILLISECOND, calMax.getMaximum(Calendar.MILLISECOND));

        setSearchStartDate(calMin.getTime());
        setSearchStartDateValid(true);
        setSearchEndDate(calMax.getTime());
        setSearchEndDateValid(true);
    }

    return manager.getAllEntities(search, new SortCriteria(sortColumn, sortAscending));
}

From source file:DateUtility.java

/**
 * This will retun the first millisecond of the month 
 * that contains the timestamp provided/* w w  w .j a  v a2  s . c  om*/
 * @param timestamp
 * @return long
 */
static public long getFirstMilliOfMonth(long timestamp, TimeZone tz) {
    GregorianCalendar cal = new GregorianCalendar();
    cal.setTimeZone(tz);
    cal.setTime(new Date(timestamp));
    cal.set(Calendar.DAY_OF_MONTH, 1);
    cal.set(Calendar.HOUR_OF_DAY, 0);
    cal.set(Calendar.MINUTE, 0);
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);

    Date date = cal.getTime();

    return date.getTime();
}

From source file:io.apiman.gateway.engine.jdbc.JdbcMetrics.java

/**
 * Process the next item in the queue.//from  w w  w  . j ava2s.com
 */
@SuppressWarnings("nls")
protected void processQueue() {
    try {
        RequestMetric metric = queue.take();
        QueryRunner run = new QueryRunner(ds);

        Calendar cal = Calendar.getInstance();
        cal.setTimeZone(TimeZone.getTimeZone("UTC"));
        cal.setTime(metric.getRequestStart());

        long rstart = cal.getTimeInMillis();
        long rend = metric.getRequestEnd().getTime();
        long duration = metric.getRequestDuration();
        cal.set(Calendar.MILLISECOND, 0);
        cal.set(Calendar.SECOND, 0);
        long minute = cal.getTimeInMillis();
        cal.set(Calendar.MINUTE, 0);
        long hour = cal.getTimeInMillis();
        cal.set(Calendar.HOUR_OF_DAY, 0);
        long day = cal.getTimeInMillis();
        cal.set(Calendar.DAY_OF_WEEK, cal.getFirstDayOfWeek());
        long week = cal.getTimeInMillis();
        cal.set(Calendar.DAY_OF_MONTH, 1);
        long month = cal.getTimeInMillis();
        String api_org_id = metric.getApiOrgId();
        String api_id = metric.getApiId();
        String api_version = metric.getApiVersion();
        String client_org_id = metric.getClientOrgId();
        String client_id = metric.getClientId();
        String client_version = metric.getClientVersion();
        String plan = metric.getPlanId();
        String user_id = metric.getUser();
        String rtype = null;
        if (metric.isFailure()) {
            rtype = "failure";
        } else if (metric.isError()) {
            rtype = "error";
        }
        long bytes_up = metric.getBytesUploaded();
        long bytes_down = metric.getBytesDownloaded();

        // Now insert a row for the metric.
        run.update("INSERT INTO gw_requests (" + "rstart, rend, duration, month, week, day, hour, minute, "
                + "api_org_id, api_id, api_version, " + "client_org_id, client_id, client_version, plan, "
                + "user_id, resp_type, bytes_up, bytes_down) VALUES (" + "?, ?, ?, ?, ?, ?, ?, ?," + "?, ?, ?,"
                + "?, ?, ?, ?," + "?, ?, ?, ?)", rstart, rend, duration, month, week, day, hour, minute,
                api_org_id, api_id, api_version, client_org_id, client_id, client_version, plan, user_id, rtype,
                bytes_up, bytes_down);
    } catch (InterruptedException ie) {
        // This means that the thread was stopped.
    } catch (Exception e) {
        // TODO better logging of this unlikely error
        System.err.println("Error adding metric to database:"); //$NON-NLS-1$
        e.printStackTrace();
        return;
    }
}