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: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;/*w ww.  j  a  v a2  s. c  o m*/
}

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

/**
 * /*from w w  w.j a v  a2  s. com*/
 * @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:net.duckling.ddl.util.Utility.java

public static String getDateCustom(Date date, String fmt) {
    Calendar calToday = Calendar.getInstance();
    calToday.set(Calendar.HOUR_OF_DAY, 0);
    Calendar calYear = Calendar.getInstance();
    calYear.set(Calendar.DAY_OF_YEAR, 1);
    Calendar cal = Calendar.getInstance();
    cal.setTime(date);//from   w  ww . j a  v a2 s .c  o m
    return (new SimpleDateFormat(fmt)).format(cal.getTime());
}

From source file:ch.cyberduck.core.ftp.parser.StingrayFTPEntryParserTest.java

/**
 * http://trac.cyberduck.ch/ticket/1198/*w  ww.  ja  va 2s . co m*/
 */
@Test
public void testFile() {
    FTPFile parsed;

    parsed = parser.parseFTPEntry("-r--r--r--          0     165100     165100 Aug  1 10:24 grau2.tif");
    assertNotNull(parsed);
    assertEquals("grau2.tif", parsed.getName());
    assertEquals(FTPFile.FILE_TYPE, parsed.getType());
    assertEquals(Calendar.AUGUST, parsed.getTimestamp().get(Calendar.MONTH));
    assertEquals(1, parsed.getTimestamp().get(Calendar.DAY_OF_MONTH));
    assertEquals(10, parsed.getTimestamp().get(Calendar.HOUR_OF_DAY));
    assertEquals(24, parsed.getTimestamp().get(Calendar.MINUTE));
    assertTrue(parsed.hasPermission(FTPFile.USER_ACCESS, FTPFile.READ_PERMISSION));
    assertTrue(parsed.hasPermission(FTPFile.GROUP_ACCESS, FTPFile.READ_PERMISSION));
    assertTrue(parsed.hasPermission(FTPFile.WORLD_ACCESS, FTPFile.READ_PERMISSION));
    assertFalse(parsed.hasPermission(FTPFile.USER_ACCESS, FTPFile.WRITE_PERMISSION));
    assertFalse(parsed.hasPermission(FTPFile.GROUP_ACCESS, FTPFile.WRITE_PERMISSION));
    assertFalse(parsed.hasPermission(FTPFile.WORLD_ACCESS, FTPFile.WRITE_PERMISSION));
    assertFalse(parsed.hasPermission(FTPFile.USER_ACCESS, FTPFile.EXECUTE_PERMISSION));
    assertFalse(parsed.hasPermission(FTPFile.GROUP_ACCESS, FTPFile.EXECUTE_PERMISSION));
    assertFalse(parsed.hasPermission(FTPFile.WORLD_ACCESS, FTPFile.EXECUTE_PERMISSION));
}

From source file:com.spoiledmilk.cykelsuperstier.break_rote.MetroData.java

public static ArrayList<ITransportationInfo> getNext3Arrivals(String line, String startStation,
        String endStation, Context context) {
    ArrayList<ITransportationInfo> ret = new ArrayList<ITransportationInfo>();
    String bufferString = Util.stringFromJsonAssets(context, "stations/" + filename);
    JsonNode actualObj = Util.stringToJsonNode(bufferString);
    JsonNode lines = actualObj.get("lines");
    for (int i = 0; i < lines.size(); i++) {
        JsonNode lineJson = lines.get(i);
        if (lineJson.get("name").asText().contains(line)) {
            Calendar calendar = Calendar.getInstance();
            int day = calendar.get(Calendar.DAY_OF_WEEK);
            if (day == 1)
                day = 6;//from   ww  w .  j av  a 2  s  . c om
            else
                day -= 2;
            int hour = calendar.get(Calendar.HOUR_OF_DAY);
            int minute = calendar.get(Calendar.MINUTE);
            int period = 0, endTime = 0; // startTime
            try {
                if ((day == 4 || day == 5) && hour >= 0 && hour <= 7) { // Friday and Saturday night
                    period = lineJson.get("timetable").get("friday_saturday_night").get(0).get("period")
                            .asInt();
                    endTime = lineJson.get("timetable").get("friday_saturday_night").get(0).get("end_time")
                            .asInt();
                } else if ((day < 4 || day == 6) && hour >= 0 && hour <= 5) { // other days at night
                    JsonNode timetableNode = lineJson.get("timetable");
                    JsonNode timetableNodeContainer = timetableNode.get("sunday_thursday_night");
                    period = timetableNodeContainer.get(0).get("period").asInt();
                    endTime = timetableNodeContainer.get(0).get("end_time").asInt();
                } else {
                    JsonNode nodeRushour = lineJson.get("timetable").get("weekdays_rushour");
                    JsonNode nodeOutsideRushour = lineJson.get("timetable").get("weekdays_outside_rushour");
                    if ((day >= 0 && day < 5) && hour >= nodeRushour.get(0).get("start_time").asInt()
                            && hour < nodeRushour.get(0).get("end_time").asInt()) {
                        endTime = nodeRushour.get(0).get("end_time").asInt();
                        period = nodeRushour.get(0).get("period").asInt();
                    } else if ((day >= 0 && day < 5) && hour >= nodeRushour.get(1).get("start_time").asInt()
                            && hour < nodeRushour.get(1).get("end_time").asInt()) {
                        endTime = nodeRushour.get(1).get("end_time").asInt();
                        period = nodeRushour.get(1).get("period").asInt();
                    } else if (hour >= nodeOutsideRushour.get(0).get("start_time").asInt()
                            && hour < nodeOutsideRushour.get(0).get("end_time").asInt()) {
                        endTime = nodeOutsideRushour.get(0).get("end_time").asInt();
                        period = nodeOutsideRushour.get(0).get("period").asInt();
                    } else {
                        endTime = nodeOutsideRushour.get(1).get("end_time").asInt();
                        period = nodeOutsideRushour.get(1).get("period").asInt();
                    }

                }
                int currentHour = hour;
                int currentMinute = minute;
                int count = 0;
                period *= getTimeBetweenStations(line, startStation, endStation, context);
                while (count < 3) {
                    for (int k = 0; k < 60 && count < 3; k += period % 60) {
                        if (k >= currentMinute) {
                            currentMinute = k % 60;
                            currentHour += period / 60;
                            String arrivalTime = (currentHour < 10 ? "0" + currentHour : "" + currentHour) + ":"
                                    + (currentMinute < 10 ? "0" + currentMinute : "" + currentMinute);
                            int destHour = currentHour + period / 60;
                            int destMinute = currentMinute + period % 60;
                            if (destMinute > 59) {
                                destHour += destMinute / 60;
                                destMinute = destMinute % 60;
                            }
                            String destTime = (destHour < 10 ? "0" + destHour : "" + destHour) + ":"
                                    + (destMinute < 10 ? "0" + destMinute : "" + destMinute);
                            ret.add(new MetroData(arrivalTime, destTime, period));
                            count++;
                        }
                    }
                    currentMinute = 0;
                    if ((++currentHour) >= endTime)
                        break;
                }
            } catch (Exception e) {
                LOG.e(e.getLocalizedMessage());
            }
            break;
        }
    }
    return ret;
}

From source file:com.example.geomesa.authorizations.AuthorizationsTutorial.java

/**
 * Creates a base filter that will return a small subset of our results. This can be tweaked to
 * return different results if desired. Currently it should return 16 results.
 *
 * @return//from w ww .  j  a  va 2  s . c  om
 *
 * @throws CQLException
 * @throws IOException
 */
static Filter createBaseFilter() throws CQLException, IOException {

    // Get a FilterFactory2 to build up our query
    FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2();

    // We are going to query for events in Ukraine during the
    // civil unrest.

    // We'll start by looking at a particular day in February of 2014
    Calendar calendar = Calendar.getInstance();
    calendar.clear();
    calendar.set(Calendar.YEAR, 2013);
    calendar.set(Calendar.MONTH, Calendar.JANUARY);
    calendar.set(Calendar.DAY_OF_MONTH, 1);
    calendar.set(Calendar.HOUR_OF_DAY, 0);
    Date start = calendar.getTime();

    calendar.set(Calendar.YEAR, 2014);
    calendar.set(Calendar.MONTH, Calendar.APRIL);
    calendar.set(Calendar.DAY_OF_MONTH, 30);
    calendar.set(Calendar.HOUR_OF_DAY, 23);
    Date end = calendar.getTime();
    //        2013-01-01T00:00:00.000Z/2014-04-30T23:00:00.000Z
    Filter timeFilter = ff.between(ff.property(GdeltFeature.Attributes.SQLDATE.getName()), ff.literal(start),
            ff.literal(end));

    // We'll bound our query spatially to Ukraine
    Filter spatialFilter = ff.bbox(GdeltFeature.Attributes.geom.getName(), 31.6, 44, 37.4, 47.75, "EPSG:4326");

    // we'll also restrict our query to only articles about the US, UK or UN
    Filter attributeFilter = ff.like(ff.property(GdeltFeature.Attributes.Actor1Name.getName()), "UNITED%");

    // Now we can combine our filters using a boolean AND operator
    Filter conjunction = ff.and(Arrays.asList(timeFilter, spatialFilter, attributeFilter));

    return conjunction;
}

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();/*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:net.seratch.taskun.util.CalendarUtil.java

 public static Calendar getCalendar(int yyyy, int mm, int dd) {
   Calendar cal = Calendar.getInstance();
   cal.set(Calendar.YEAR, yyyy);//  w  w  w. j a v  a2  s  .  c  o m
   cal.set(Calendar.MONTH, mm - 1);
   cal.set(Calendar.DATE, dd);
   cal.set(Calendar.HOUR_OF_DAY, 0);
   cal.set(Calendar.MINUTE, 0);
   cal.set(Calendar.SECOND, 0);
   cal.set(Calendar.MILLISECOND, 0);
   return cal;
}

From source file:CalendarDemo.java

public void format() {

    // Tell the calendar what date/time to format
    calendar.setTime(timeNow);/*  w  w w .  j a v  a  2  s  . c o  m*/

    // print out most of the known fields
    System.out.println("ERA: " + calendar.get(Calendar.ERA));
    System.out.println("YEAR: " + calendar.get(Calendar.YEAR));
    System.out.println("MONTH: " + calendar.get(Calendar.MONTH));
    System.out.println("WEEK_OF_YEAR: " + calendar.get(Calendar.WEEK_OF_YEAR));
    System.out.println("WEEK_OF_MONTH: " + calendar.get(Calendar.WEEK_OF_MONTH));
    System.out.println("DATE: " + calendar.get(Calendar.DATE));
    System.out.println("DAY_OF_MONTH: " + calendar.get(Calendar.DAY_OF_MONTH));
    System.out.println("DAY_OF_YEAR: " + calendar.get(Calendar.DAY_OF_YEAR));
    System.out.println("DAY_OF_WEEK: " + calendar.get(Calendar.DAY_OF_WEEK));
    System.out.println("DAY_OF_WEEK_IN_MONTH: " + calendar.get(Calendar.DAY_OF_WEEK_IN_MONTH));
    System.out.println("AM_PM: " + calendar.get(Calendar.AM_PM));
    System.out.println("HOUR: " + calendar.get(Calendar.HOUR));
    System.out.println("HOUR_OF_DAY: " + calendar.get(Calendar.HOUR_OF_DAY));
    System.out.println("MINUTE: " + calendar.get(Calendar.MINUTE));
    System.out.println("SECOND: " + calendar.get(Calendar.SECOND));
    System.out.println("MILLISECOND: " + calendar.get(Calendar.MILLISECOND));
    System.out.println("ZONE_OFFSET: " + (calendar.get(Calendar.ZONE_OFFSET) / (60 * 60 * 1000)));
    System.out.println("DST_OFFSET: " + (calendar.get(Calendar.DST_OFFSET) / (60 * 60 * 1000)));
}

From source file:helper.lang.DateHelperTest.java

@Test
public void testAsUtcDayDate() {
    Calendar localTime = Calendar.getInstance(TimeZone.getTimeZone("CST"));
    Calendar cal = DateHelper.asUtcDay(localTime.getTime());
    assertEquals(0, cal.get(Calendar.MILLISECOND));
    assertEquals(0, cal.get(Calendar.MINUTE));
    assertEquals(0, cal.get(Calendar.HOUR));
    assertEquals(0, cal.get(Calendar.HOUR_OF_DAY));
    assertEquals(DateHelper.UTC_TIME_ZONE, cal.getTimeZone());
    //assertEquals(TimeZone.getTimeZone("CST"), localTime.getTimeZone());
    //assertEquals(localTime.get(Calendar.YEAR), cal.get(Calendar.YEAR));
    //assertEquals(localTime.get(Calendar.MONTH), cal.get(Calendar.MONTH));
    //assertEquals(localTime.get(Calendar.DATE), cal.get(Calendar.DATE));
}