List of usage examples for java.util Calendar HOUR_OF_DAY
int HOUR_OF_DAY
To view the source code for java.util Calendar HOUR_OF_DAY.
Click Source Link
get
and set
indicating the hour of the day. From source file:com.spoiledmilk.cykelsuperstier.break_rote.STrainData.java
public static ArrayList<ITransportationInfo> getNext3Arrivals(String stationFrom, String stationTo, String line, Context context) {/*from w w w . j ava 2s . co m*/ ArrayList<ITransportationInfo> ret = new ArrayList<ITransportationInfo>(); try { String bufferString = Util.stringFromJsonAssets(context, "stations/" + filename); JsonNode actualObj = Util.stringToJsonNode(bufferString); JsonNode lines = actualObj.get("timetable"); // find the data for the current transportation line for (int i = 0; i < lines.size(); i++) { JsonNode lineJson = lines.get(i); String[] sublines = line.split(","); for (int ii = 0; ii < sublines.length; ii++) { if (lineJson.get("line").asText().equalsIgnoreCase(sublines[ii].trim())) { int day = Calendar.getInstance().get(Calendar.DAY_OF_WEEK); if (day == 1) day = 6; else day -= 2; int hour = Calendar.getInstance().get(Calendar.HOUR_OF_DAY); int minute = Calendar.getInstance().get(Calendar.MINUTE); JsonNode stationData = null; if ((day == 4 || day == 5) && isFridaySaturdayNight(lineJson.get("night-after-friday-saturday"), hour)) { // night after Friday or Saturday stationData = lineJson.get("night-after-friday-saturday"); } else if (day < 5) { // weekdays stationData = lineJson.get("weekdays"); } else { // weekend stationData = lineJson.get("weekend"); } JsonNode stations = stationData.get("data"); int[] AStationMinutes = null, BStationMinutes = null; // find the data for the start and end station and choose the direction direction = NOT_SET; for (int j = 0; j < stations.size(); j++) { JsonNode st = stations.get(j); if (st.get("station").asText().equalsIgnoreCase(stationFrom) && direction == NOT_SET && AStationMinutes == null) { direction = DEPARTURE; AStationMinutes = getMinutesArray(st.get("departure").asText()); } else if (st.get("station").asText().equalsIgnoreCase(stationFrom) && AStationMinutes == null) { AStationMinutes = getMinutesArray(st.get("arrival").asText()); break; } else if (st.get("station").asText().equalsIgnoreCase(stationTo) && direction == NOT_SET && BStationMinutes == null) { direction = ARRIVAL; BStationMinutes = getMinutesArray(st.get("departure").asText()); } else if (st.get("station").asText().equalsIgnoreCase(stationTo) && BStationMinutes == null) { BStationMinutes = getMinutesArray(st.get("arrival").asText()); break; } } if (AStationMinutes == null || BStationMinutes == null) continue; JsonNode subLines = direction == DEPARTURE ? stationData.get("departure") : stationData.get("arrival"); JsonNode subLine = subLines.get(0); if (hasTrain(hour, subLine.get("night").asText(), subLine.get("day").asText())) { int count = 0; for (int k = 0; k < AStationMinutes.length; k++) { if (minute <= AStationMinutes[k]) { int arrivalHour = hour; int time = BStationMinutes[k] - AStationMinutes[k]; if (AStationMinutes[k] > BStationMinutes[k]) { arrivalHour++; time = 60 - AStationMinutes[k] + BStationMinutes[k]; } ret.add(new STrainData( (hour < 10 ? "0" + hour : "" + hour) + ":" + (AStationMinutes[k] < 10 ? "0" + AStationMinutes[k] : "" + AStationMinutes[k]), (arrivalHour < 10 ? "0" + arrivalHour : "" + arrivalHour) + ":" + (BStationMinutes[k] < 10 ? "0" + BStationMinutes[k] : "" + BStationMinutes[k]), time)); if (++count == 3) break; } } // second pass to get the times for the next hour hour++; for (int k = 0; k < AStationMinutes.length && count < 3; k++) { int arrivalHour = hour; int time = BStationMinutes[k] - AStationMinutes[k]; if (AStationMinutes[k] > BStationMinutes[k]) { arrivalHour++; time = 60 - AStationMinutes[k] + BStationMinutes[k]; } ret.add(new STrainData( (hour < 10 ? "0" + hour : "" + hour) + ":" + (AStationMinutes[k] < 10 ? "0" + AStationMinutes[k] : "" + AStationMinutes[k]), (arrivalHour < 10 ? "0" + arrivalHour : "" + arrivalHour) + ":" + (BStationMinutes[k] < 10 ? "0" + BStationMinutes[k] : "" + BStationMinutes[k]), time)); } } return ret; } } } } catch (Exception e) { if (e != null && e.getLocalizedMessage() != null) LOG.e(e.getLocalizedMessage()); } return ret; }
From source file:adalid.commons.util.TimeUtils.java
public static synchronized Date currentDate() { calendar.setTimeInMillis(currentTimeMillis()); calendar.set(Calendar.HOUR_OF_DAY, 0); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.SECOND, 0); calendar.set(Calendar.MILLISECOND, 0); return new Date(calendar.getTimeInMillis()); }
From source file:net.kamhon.ieagle.util.DateUtil.java
public static Date formatDateByTime(Date date, int hour, int minute, int second, int milisecond) { Calendar calendar = setTime(date); calendar.set(Calendar.HOUR_OF_DAY, hour); calendar.set(Calendar.MINUTE, minute); calendar.set(Calendar.SECOND, second); calendar.set(Calendar.MILLISECOND, milisecond); return calendar.getTime(); }
From source file:org.psidnell.omnifocus.expr.ExpressionFunctionsTest.java
@Test public void testDateRoundToDay() throws ParseException { Date date1 = ExpressionFunctions.roundToDay(new Date()); Calendar cal2 = new GregorianCalendar(); assertNotEquals(date1, cal2.getTime()); cal2.set(Calendar.HOUR_OF_DAY, 0); cal2.set(Calendar.MINUTE, 0); cal2.set(Calendar.SECOND, 0); cal2.set(Calendar.MILLISECOND, 0); assertEquals(date1, cal2.getTime()); }
From source file:Controller.Movimientos.generatePDF.java
public void generateAgendaEmpleados() { mm = new Model_Movimientos(); try {/* ww w . j av a 2 s . co m*/ Calendar calendar = Calendar.getInstance(); int dayOfMonth = calendar.get(Calendar.DAY_OF_MONTH); int monthOfYear = calendar.get(Calendar.MONTH); int year = calendar.get(Calendar.YEAR); int hour = calendar.get(Calendar.HOUR_OF_DAY); int min = calendar.get(Calendar.MINUTE); int sec = calendar.get(Calendar.SECOND); Document documento = new Document();//Creamos el documento FileOutputStream ficheroPdf = new FileOutputStream("agendaEmpleados" + dayOfMonth + "--" + monthOfYear + "--" + year + " " + hour + ";" + min + ";" + sec + ".pdf");//Abrimos el flujo y le asignamos nombre al pdf y su direccion PdfWriter.getInstance(documento, ficheroPdf).setInitialLeading(20);//Instanciamos el documento con el fichero documento.open();//Abrimos el documento documento.add(new Paragraph("Lista Empleados", FontFactory.getFont("Calibri", 30, Font.BOLD, BaseColor.BLACK)));//Le indicamos el tipo de letra, el tamanio, el estilo y el color de la letra documento.add(new Paragraph("___________________________"));//Realiza un salto de linea Iterator it; it = mm.getCrews().iterator(); while (it.hasNext()) { Crew c = (Crew) it.next(); System.out.println("" + c.getEmail().toString()); documento.add(new Paragraph("")); //Le decimos que nos imprima el Dni, Nombre y Apellidos del cliente, contenidos en el objeto Cliente y le indicamos el tipo de letra, tamanio, estilo y color de la letra documento.add(new Paragraph("Nombre: " + c.getName(), FontFactory.getFont("Calibri", 20, Font.BOLD, BaseColor.BLACK))); documento.add(new Paragraph("Apellidos: " + c.getSurname(), FontFactory.getFont("Calibri", 20, Font.BOLD, BaseColor.BLACK))); documento.add(new Paragraph("Email: " + c.getEmail(), FontFactory.getFont("Calibri", 20, Font.BOLD, BaseColor.BLACK))); documento.add(new Paragraph("Telfono: " + c.getPhoneNumber(), FontFactory.getFont("Calibri", 20, Font.BOLD, BaseColor.BLACK))); documento.add(new Paragraph("Nickname: " + c.getNickname(), FontFactory.getFont("Calibri", 20, Font.BOLD, BaseColor.BLACK))); documento.add(new Paragraph("Contrasea: " + c.getPassword(), FontFactory.getFont("Calibri", 20, Font.BOLD, BaseColor.BLACK))); documento.add(new Paragraph("Puesto: " + c.getRole(), FontFactory.getFont("Calibri", 20, Font.BOLD, BaseColor.BLACK))); documento.add(new Paragraph(" ")); documento.add(new Paragraph(" ")); documento.add(new Paragraph( "______________________________________________________________________________")); } documento.close();//Cerramos el flujo con el documento JOptionPane.showMessageDialog(null, "Se ha creado agenda de Empleados."); } catch (DocumentException ex) { Logger.getLogger(generatePDF.class.getName()).log(Level.SEVERE, null, ex); } catch (FileNotFoundException ex) { Logger.getLogger(generatePDF.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:gbc.jtimecalc.AbstractTimeDifferenceCalculatorTest.java
protected static Calendar prepareCalendar(int year, int month, int day, int hour, int minute, int second, int millisecond) { Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.MILLISECOND, millisecond); calendar.set(Calendar.SECOND, second); calendar.set(Calendar.MINUTE, minute); calendar.set(Calendar.HOUR_OF_DAY, hour); calendar.set(Calendar.DATE, day); calendar.set(Calendar.MONTH, month); calendar.set(Calendar.YEAR, year); return calendar; }
From source file:de.uzk.hki.da.at.ATUseCaseAudit.java
@Before public void setUp() throws IOException { // set object to older creationdate than one day Calendar now = Calendar.getInstance(); now.add(Calendar.HOUR_OF_DAY, -25); object = ath.putPackageToStorage(IDENTIFIER, ORIGINAL_NAME, CONTAINER_NAME, now.getTime(), 100); }
From source file:ISO8601DateFormat.java
/** * @see java.text.DateFormat#parse(String, ParsePosition) *//*from w ww .j av a 2 s . co m*/ public Date parse(String text, ParsePosition pos) { int i = pos.getIndex(); try { int year = Integer.valueOf(text.substring(i, i + 4)).intValue(); i += 4; if (text.charAt(i) != '-') { throw new NumberFormatException(); } i++; int month = Integer.valueOf(text.substring(i, i + 2)).intValue() - 1; i += 2; if (text.charAt(i) != '-') { throw new NumberFormatException(); } i++; int day = Integer.valueOf(text.substring(i, i + 2)).intValue(); i += 2; calendar.set(year, month, day); calendar.set(Calendar.HOUR_OF_DAY, 0); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.SECOND, 0); calendar.set(Calendar.MILLISECOND, 0); // no parts of a second i = parseTZ(i, text); } catch (NumberFormatException ex) { pos.setErrorIndex(i); return null; } catch (IndexOutOfBoundsException ex) { pos.setErrorIndex(i); return null; } finally { pos.setIndex(i); } return calendar.getTime(); }
From source file:com.hemou.android.util.StrUtils.java
/** * {@link https://en.wikipedia.org/wiki/List_of_time_zones_by_country} * @param time// ww w .ja v a 2 s .com * @return */ public static String convertTimeWithTimeZome(long time) { Calendar cal = Calendar.getInstance(); cal.setTimeZone(TimeZone.getTimeZone("UTC")); cal.setTimeInMillis(time); return (cal.get(Calendar.YEAR) + " " + (cal.get(Calendar.MONTH) + 1) + " " + cal.get(Calendar.DAY_OF_MONTH) + " " + cal.get(Calendar.HOUR_OF_DAY) + ":" + cal.get(Calendar.MINUTE)); }
From source file:org.openmrs.module.uiframeworkpatientsummarysupport.fragment.controller.PatientObsFlowsheetFragmentController.java
/** * This method was actually added in core as of 1.9 *///from w w w . j a v a 2 s. co m private static Date startOfDay(Date date) { if (date == null) return null; Calendar c = Calendar.getInstance(); c.setTime(date); c.set(Calendar.HOUR_OF_DAY, 0); c.set(Calendar.MINUTE, 0); c.set(Calendar.SECOND, 0); c.set(Calendar.MILLISECOND, 0); return c.getTime(); }