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:com.ar.dev.tierra.api.dao.impl.ChartDAOImpl.java

@SuppressWarnings("unchecked")
@Override//from   ww  w.  ja  v a  2 s .  c  om
public List<Chart> getVentaVendedores(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));
        vendedorFactura.setProjection(Projections.rowCount());
        Long counter = (Long) facturas.uniqueResult();
        chart.setValue(counter.intValue());
        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.adobe.acs.commons.http.headers.impl.DailyExpiresHeaderFilterTest.java

@Test
public void testAdjustExpiresFuture() throws Exception {

    Calendar actual = Calendar.getInstance();
    actual.add(Calendar.MINUTE, 1);
    actual.set(Calendar.SECOND, 0);
    actual.set(Calendar.MILLISECOND, 0);

    Calendar expected = Calendar.getInstance();
    expected.setTime(actual.getTime());//from   w w w . j  av a2s.  c  o  m

    filter.adjustExpires(actual);

    assertTrue(DateUtils.isSameInstant(expected, actual));
}

From source file:DateUtils.java

public static String getTimestamp() {
    Calendar cal = Calendar.getInstance();
    cal.setTime(new Date());

    int year = cal.get(Calendar.YEAR);
    int month = cal.get(Calendar.MONTH) + 1;
    int day = cal.get(Calendar.DAY_OF_MONTH);
    int hours = cal.get(Calendar.HOUR_OF_DAY);
    // use 24 hour clock
    int minutes = cal.get(Calendar.MINUTE);
    int seconds = cal.get(Calendar.SECOND);
    int milli = cal.get(Calendar.MILLISECOND);

    return "" + year + "-" + month + "-" + day + "_" + formatTime(hours, minutes, seconds, milli);
}

From source file:com.linuxbox.enkive.teststats.StatsWeekGrainTest.java

@BeforeClass
public static void setUp() throws ParseException, GathererException {
    coll = TestHelper.GetTestCollection();
    client = TestHelper.BuildClient();/*from w ww . j  a v a 2  s  .  c  o m*/
    grain = new WeekConsolidator(client);

    List<Map<String, Object>> stats = (new DayConsolidator(client)).consolidateData();
    Map<String, Object> timeMap = createMap();
    Calendar cal = Calendar.getInstance();
    cal.set(Calendar.MILLISECOND, 0);
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MINUTE, 0);
    cal.set(Calendar.HOUR, 0);
    for (int i = 0; i < 10; i++) {
        if (i == 5) {
            cal.add(Calendar.WEEK_OF_MONTH, -1);
        }
        timeMap.put(CONSOLIDATION_MAX, cal.getTime());
        timeMap.put(CONSOLIDATION_MIN, cal.getTime());
        for (Map<String, Object> data : stats) {
            data.put(STAT_TIMESTAMP, timeMap);
        }
        client.storeData(stats);
    }
    dataCount = coll.count();
}

From source file:net.netheos.pcsapi.providers.hubic.SwiftTest.java

@Test
public void testParseTimestamp() {
    // Check we won't break if a header is missing :
    Headers headers = new Headers();
    Date timestamp = Swift.parseTimestamp(headers);
    assertNull(timestamp);/*w  w  w . ja v a 2  s  . co  m*/

    headers.addHeader("X-Timestamp", "1383925113.43900"); // 2013-11-08T16:38:33.439+01:00
    timestamp = Swift.parseTimestamp(headers);

    Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
    cal.setTime(timestamp);
    System.out.println(timestamp);
    assertEquals(2013, cal.get(Calendar.YEAR));
    assertEquals(Calendar.NOVEMBER, cal.get(Calendar.MONTH));
    assertEquals(8, cal.get(Calendar.DAY_OF_MONTH));
    assertEquals(15, cal.get(Calendar.HOUR_OF_DAY));
    assertEquals(38, cal.get(Calendar.MINUTE));
    assertEquals(33, cal.get(Calendar.SECOND));
    assertEquals(439, cal.get(Calendar.MILLISECOND));

    checkTimestamp("1383925113.430723", new Date(1383925113430L));
    checkTimestamp("1383925113.43900", new Date(1383925113439L));
    checkTimestamp("1383925113.439", new Date(1383925113439L));
    checkTimestamp("1383925113.43", new Date(1383925113430L));
    checkTimestamp("1383925113.4", new Date(1383925113400L));
    checkTimestamp("1383925113.", new Date(1383925113000L));
    checkTimestamp("1383925113", new Date(1383925113000L));
}

From source file:com.google.orkut.client.api.Util.java

static String getFormattedTimestamp(long timeMillis) {
    Calendar cal = Calendar.getInstance(TimeZone.getTimeZone(Constants.DateFormatter.UTC));
    cal.setTimeInMillis(timeMillis);/*  w w w  .jav  a2 s.  c  o  m*/
    StringBuilder date = new StringBuilder();
    date.append(cal.get(Calendar.YEAR));
    date.append(Constants.DateFormatter.DATE_SEPARATOR);
    date.append(padSingleDigitNum(cal.get(Calendar.MONTH) + 1));
    date.append(Constants.DateFormatter.DATE_SEPARATOR);
    date.append(padSingleDigitNum(cal.get(Calendar.DATE)));
    date.append(Constants.DateFormatter.DATE_DELIM);
    date.append(padSingleDigitNum(cal.get(Calendar.HOUR)));
    date.append(Constants.DateFormatter.TIME_SEPARATOR);
    date.append(padSingleDigitNum(cal.get(Calendar.MINUTE)));
    date.append(Constants.DateFormatter.TIME_SEPARATOR);
    date.append(padSingleDigitNum(cal.get(Calendar.SECOND)));
    date.append(Constants.DateFormatter.TIME_DELIM);
    return date.toString();
}

From source file:com.intuit.tank.report.JobReportOptions.java

public Date getStartTime() {
    Date ret = null;/*from w ww.  j av  a  2s.co  m*/
    if (startDate != null) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(startDate);
        cal.set(Calendar.HOUR_OF_DAY, 0);
        cal.set(Calendar.MINUTE, 0);
        cal.set(Calendar.SECOND, 0);
        if (StringUtils.isNotBlank(startTimeString)) {
            try {
                Calendar parsed = Calendar.getInstance();
                parsed.setTime(tf.parse(startTimeString));
                cal.set(Calendar.HOUR_OF_DAY, parsed.get(Calendar.HOUR_OF_DAY));
                cal.set(Calendar.MINUTE, parsed.get(Calendar.MINUTE));
            } catch (ParseException e) {
                LOG.warn("Could not parse time string " + startTimeString);
            }
        }
        ret = cal.getTime();
    }
    return ret;
}

From source file:com.liusoft.dlog4j.util.DateUtils.java

/**
 * //from   ww w  .  ja  v a 2  s . c  o  m
 * @param cal
 */
public static void resetTime(Calendar cal) {
    cal.set(Calendar.HOUR_OF_DAY, 0);
    cal.set(Calendar.MINUTE, 0);
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);
}

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

@Override
public List<Factura> getDiary() {
    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.asc("idFactura"));
    criteria.add(Restrictions.not(Restrictions.in("estado", new String[] { "RESERVADO" })));
    criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
    criteria.addOrder(Order.desc("idFactura"));
    List<Factura> list = criteria.list();
    return list;//from w w  w  .  j  a v a  2s.c  om
}

From source file:Main.java

/**
 * Parse a date from ISO-8601 formatted string. It expects a format yyyy-MM-ddThh:mm:ss[.sss][Z|[+-]hh:mm]
 *
 * @param date ISO string to parse in the appropriate format.
 * @return the parsed date//from   ww w . j  a  va  2  s. c  om
 * @throws IllegalArgumentException if the date is not in the appropriate format
 */
public static Date parse(String date) {
    try {
        int offset = 0;

        // extract year
        int year = parseInt(date, offset, offset += 4);
        checkOffset(date, offset, '-');

        // extract month
        int month = parseInt(date, offset += 1, offset += 2);
        checkOffset(date, offset, '-');

        // extract day
        int day = parseInt(date, offset += 1, offset += 2);
        checkOffset(date, offset, 'T');

        // extract hours, minutes, seconds and milliseconds
        int hour = parseInt(date, offset += 1, offset += 2);
        checkOffset(date, offset, ':');

        int minutes = parseInt(date, offset += 1, offset += 2);
        checkOffset(date, offset, ':');

        int seconds = parseInt(date, offset += 1, offset += 2);
        // milliseconds can be optional in the format
        int milliseconds = 0; // always use 0 otherwise returned date will include millis of current time
        if (date.charAt(offset) == '.') {
            checkOffset(date, offset, '.');
            milliseconds = parseInt(date, offset += 1, offset += 3);
        }

        // extract timezone
        String timezoneId;
        char timezoneIndicator = date.charAt(offset);
        if (timezoneIndicator == '+' || timezoneIndicator == '-') {
            timezoneId = GMT_ID + date.substring(offset);
        } else if (timezoneIndicator == 'Z') {
            timezoneId = GMT_ID;
        } else {
            throw new IndexOutOfBoundsException("Invalid time zone indicator " + timezoneIndicator);
        }
        TimeZone timezone = TimeZone.getTimeZone(timezoneId);
        if (!timezone.getID().equals(timezoneId)) {
            throw new IndexOutOfBoundsException();
        }

        Calendar calendar = new GregorianCalendar(timezone);
        calendar.setLenient(false);
        calendar.set(Calendar.YEAR, year);
        calendar.set(Calendar.MONTH, month - 1);
        calendar.set(Calendar.DAY_OF_MONTH, day);
        calendar.set(Calendar.HOUR_OF_DAY, hour);
        calendar.set(Calendar.MINUTE, minutes);
        calendar.set(Calendar.SECOND, seconds);
        calendar.set(Calendar.MILLISECOND, milliseconds);

        return calendar.getTime();
    } catch (IndexOutOfBoundsException e) {
        throw new IllegalArgumentException("Failed to parse date " + date, e);
    } catch (NumberFormatException e) {
        throw new IllegalArgumentException("Failed to parse date " + date, e);
    } catch (IllegalArgumentException e) {
        throw new IllegalArgumentException("Failed to parse date " + date, e);
    }
}