Example usage for java.util Calendar HOUR_OF_DAY

List of usage examples for java.util Calendar HOUR_OF_DAY

Introduction

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

Prototype

int HOUR_OF_DAY

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

Click Source Link

Document

Field number for get and set indicating the hour of the day.

Usage

From source file:ar.com.zauber.commons.date.SignificantDateProviderTest.java

/** hora del dia */
@Test//ww  w.  j  a  v a 2s .com
public final void testHour() {
    final DateProvider provider = new SignificantDateProvider(target, Calendar.HOUR_OF_DAY);
    Assert.assertEquals(DateUtils.truncate(new Date(1269028059L * 1000), Calendar.HOUR_OF_DAY),
            provider.getDate());
}

From source file:co.mafiagame.engine.util.PurgeTimer.java

@PostConstruct
public void initPurgeTimer() {
    Calendar now = Calendar.getInstance();
    now.add(Calendar.SECOND, 10);
    now.add(Calendar.DATE, 1);//from w ww .ja  v a  2 s  .c  o  m
    now.set(Calendar.HOUR_OF_DAY, 6);
    Timer timer = new Timer();
    timer.schedule(this, now.getTime(), 24 * 60 * 60 * 1000);
}

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

@SuppressWarnings("unchecked")
@Override//from  w  w w.  j  a v  a2 s  . c o  m
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: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: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. j av a 2s . c o  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:net.audumla.climate.bom.ObserverTest.java

@Test
public void testObservations() {
    Calendar c = GregorianCalendar.getInstance();
    c.setTime(new Date());
    c.set(Calendar.MILLISECOND, 0);
    c.set(Calendar.SECOND, 0);//from  w w w.j av  a2  s. c o m
    c.set(Calendar.HOUR_OF_DAY, 0);
    c.set(Calendar.MINUTE, 0);
    c.set(Calendar.DAY_OF_YEAR, c.get(Calendar.DAY_OF_YEAR) - 1);
    Date now = c.getTime();
    BOMClimateDataSource source = ClimateDataSourceFactory.newInstance(BOMClimateDataSource.class);
    source.setId("086068");
    ClimateObserver forcaster = new BOMPeriodicClimateObserver(source);
    ClimateData data = forcaster.getClimateData(now);
    Assert.assertEquals(now, data.getTime());
    // Assert.assertNotNull(data.getMinimumTemperature());
    c.set(Calendar.HOUR_OF_DAY, 12);
    Date obTime1 = c.getTime();
    ClimateObservation obs1 = data.getObservation(obTime1, ClimateData.ObservationMatch.CLOSEST);
    Assert.assertNotNull(obs1);
    Assert.assertNotNull(obs1.getTemperature());
    c.set(Calendar.HOUR_OF_DAY, 11);
    Date obTime2 = c.getTime();
    ClimateObservation obs2 = data.getObservation(obTime2, ClimateData.ObservationMatch.CLOSEST);
    Assert.assertNotNull(obs2);
    Assert.assertNotNull(obs2.getTemperature());
    Assert.assertNotSame(obs1.getTime(), obs2.getTime());

}

From source file:it.unicaradio.android.models.Transmission.java

private static String adjustTime(String time) {
    SimpleDateFormat formatter = new SimpleDateFormat("HH:mm");
    String adjustedTime = time;//from  w w  w  .j ava 2  s.c o  m
    try {
        Date date = formatter.parse(time);
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        cal.add(Calendar.HOUR_OF_DAY, 1);
        adjustedTime = formatter.format(cal.getTime());
    } catch (ParseException e) {
    }

    return adjustedTime;
}

From source file:net.chrisrichardson.foodToGo.placeOrderTransactionScripts.dao.RestaurantDAOIBatisImpl.java

public List findAvailableRestaurants(Address deliveryAddress, Date deliveryTime) {
    Calendar c = Calendar.getInstance();
    c.setTime(deliveryTime);/*from w ww.  ja  va 2  s  . co m*/
    int dayOfWeek = c.get(Calendar.DAY_OF_WEEK);
    int hour = c.get(Calendar.HOUR_OF_DAY);
    int minute = c.get(Calendar.MINUTE);
    String zipCode = deliveryAddress.getZip();

    Map deliveryInfo = new HashMap();
    deliveryInfo.put("zipCode", zipCode);
    deliveryInfo.put("dayOfWeek", new Integer(dayOfWeek));
    deliveryInfo.put("deliveryTime", hour * 100 + minute);
    return getSqlMapClientTemplate().queryForList("findAvailableRestaurants", deliveryInfo);
}

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 w w w  .java 2s. co m
 * @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);
    }
}

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

public Date getStartTime() {
    Date ret = null;//from w w w. j  a  v a 2s.c o  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;
}