List of usage examples for java.util Calendar HOUR
int HOUR
To view the source code for java.util Calendar HOUR.
Click Source Link
get
and set
indicating the hour of the morning or afternoon. From source file:tr.edu.gsu.peralab.mobilesensing.web.service.UserService.java
private void calculatePeriod(long hours, int index, Calendar startTime, Calendar endTime, ActivityMapResponse response) {/*from ww w . jav a2s . c o m*/ if (hours <= 1) { startTime.add(Calendar.MINUTE, -(index * 10)); endTime.add(Calendar.MONTH, 10 - (index * 10)); response.setPeriod(String.valueOf(startTime.get(Calendar.MINUTE))); } else if (hours <= 6) { startTime.add(Calendar.HOUR, -index); endTime.add(Calendar.HOUR, 1 - index); response.setPeriod(String.valueOf(startTime.get(Calendar.HOUR))); } else if (hours <= 24) { SimpleDateFormat dateFormat = new SimpleDateFormat("h:mm a", Locale.forLanguageTag("TR")); startTime.add(Calendar.HOUR, -(index * 4)); endTime.add(Calendar.HOUR, 4 - (index * 4)); response.setPeriod( dateFormat.format(startTime.getTime()) + " - " + dateFormat.format(endTime.getTime())); } else if (hours <= 144) { startTime.add(Calendar.DAY_OF_MONTH, -index); endTime.add(Calendar.DAY_OF_MONTH, 1 - index); response.setPeriod( new SimpleDateFormat("d MMM", Locale.forLanguageTag("TR")).format(startTime.getTime())); } else if (hours <= 720) { SimpleDateFormat dateFormat = new SimpleDateFormat("d MMM", Locale.forLanguageTag("TR")); startTime.add(Calendar.DAY_OF_MONTH, -((index + 1) * 5)); endTime.add(Calendar.DAY_OF_MONTH, 5 - ((index + 1) * 5)); response.setPeriod( dateFormat.format(startTime.getTime()) + " - " + dateFormat.format(endTime.getTime())); } else { startTime.add(Calendar.MONTH, -(index + 1)); endTime.add(Calendar.MONTH, -index); response.setPeriod( new SimpleDateFormat("MMM", Locale.forLanguageTag("TR")).format(startTime.getTime())); } }
From source file:helper.lang.DateHelperTest.java
@Test public void testTodayUtc() { Calendar localTime = Calendar.getInstance(DateHelper.UTC_TIME_ZONE); Calendar cal = DateHelper.todayUtc(); 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)); assertEquals(DateHelper.UTC_TIME_ZONE, cal.getTimeZone()); 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)); }
From source file:gov.nih.nci.ncicb.tcga.dcc.dam.service.FilePackagerEnqueuer.java
/** * Return the <code>Date</code> at which the archive should be scheduled for deletion * * @param immediate <code>true</code> if it should be scheduled immediately, <code>false<code> otherwise * @return the <code>Date</code> at which the archive should be scheduled for deletion *///w w w .java 2s . c om private Date getDateForArchiveDeletionSchedule(boolean immediate) { final Calendar now = Calendar.getInstance(); if (!immediate) { now.add(Calendar.HOUR, getHoursTillDeletion()); } return now.getTime(); }
From source file:com.orange.oidc.tim.service.TokensKeys.java
String getExpires() { if (expires != null && timems != 0) { Calendar cal = Calendar.getInstance(); cal.setTimeInMillis(timems);/* w ww . j a v a 2s .co m*/ return "" + cal.get(Calendar.DAY_OF_MONTH) + "/" + cal.get(Calendar.MONTH) + "/" + cal.get(Calendar.YEAR) + " " + cal.get(Calendar.HOUR) + ":" + cal.get(Calendar.MINUTE) + ":" + cal.get(Calendar.SECOND); } else if (expires != null) { Calendar cal = Calendar.getInstance(); cal = fromStringToDate(expires); if (cal != null) { return "" + cal.get(Calendar.DAY_OF_MONTH) + "/" + cal.get(Calendar.MONTH) + "/" + cal.get(Calendar.YEAR) + " " + cal.get(Calendar.HOUR) + ":" + cal.get(Calendar.MINUTE) + ":" + cal.get(Calendar.SECOND); } } return ""; }
From source file:com.simphony.managedbeans.ItineraryBean.java
/** * Actualizamos el usuario// w w w . j a v a2s.co m * * @return * @throws com.simphony.exceptions.PersonException */ public String update(User user) throws ItineraryException { Cost c = this.costService.getCostRepository().findByOriDes(this.itinerary.getOrigin().getId(), this.itinerary.getDestiny().getId()); Calendar calItinerary = Calendar.getInstance(); calItinerary.setTime(this.itinerary.getDepartureTime()); Calendar calCost = Calendar.getInstance(); calCost.setTime(c.getRouteTime()); calItinerary.add(Calendar.HOUR, calCost.get(Calendar.HOUR)); Itinerary itineraryUpdated = this.itineraryService.getItineraryRepository().findOne(this.itinerary.getId()); if (itineraryUpdated == null) { throw new ItineraryException(mp.getValue("cat_itinerary") + " " + mp.getValue("not_founded")); } this.itinerary.setUser(user); this.itinerary.setCheckTime(calItinerary.getTime()); if (itinerary.getRoute() == null) { this.itinerary.setTypeOfRoute("L"); } else this.itinerary.setTypeOfRoute("P"); itineraryUpdated.update(this.itinerary); this.itineraryService.getItineraryRepository().save(itineraryUpdated); GrowlBean.simplyInfoMessage(mp.getValue("msj_modified"), mp.getValue("msj_record_modified") + this.itinerary.getOrigin().getDescription()); itinerary = new Itinerary(); return toItineraries(); }
From source file:org.wiztools.commons.DateUtil.java
/** * Test of getAsISODateTimeString method, of class DateUtil. *///from ww w . j a v a 2 s. c o m @Test public void testGetAsISODateTimeString() { System.out.println("getAsISODateTimeString"); Calendar c = Calendar.getInstance(); c.clear(); c.set(Calendar.YEAR, 1979); c.set(Calendar.MONTH, 1); // 1 means Feb. c.set(Calendar.DATE, 15); c.set(Calendar.HOUR, 5); c.set(Calendar.MINUTE, 5); c.set(Calendar.SECOND, 5); Date date = c.getTime(); String expResult = "1979-02-15T05:05:05"; String result = DateUtil.getAsISODateTimeString(date); assertEquals(expResult, result); }
From source file:org.openmrs.module.patientportaltoolkit.fragment.controller.AddRelationshipFragmentController.java
private Date updateAge(String birthdate, String dateformat, String age) throws java.text.ParseException { SimpleDateFormat df = new SimpleDateFormat(); if (!"".equals(dateformat)) { dateformat = dateformat.toLowerCase().replaceAll("m", "M"); } else {/* w ww.j a v a 2 s . co m*/ dateformat = new String("MM/dd/yyyy"); } df.applyPattern(dateformat); Calendar cal = Calendar.getInstance(); cal.clear(Calendar.HOUR); cal.clear(Calendar.MINUTE); cal.clear(Calendar.SECOND); cal.clear(Calendar.MILLISECOND); if ("".equals(birthdate)) { if ("".equals(age)) { return cal.getTime(); } try { cal.add(Calendar.YEAR, -(Integer.parseInt(age))); } catch (NumberFormatException nfe) { log.error("Error during adding date into calendar", nfe); } return cal.getTime(); } else { cal.setTime(df.parse(birthdate)); } return cal.getTime(); }
From source file:edu.ku.brc.specify.toycode.mexconabio.MexConvToSQL.java
/** * //from w ww .java 2 s. co m */ public void process(final String databaseName) { boolean doingMapTable = false; cal.set(Calendar.SECOND, 0); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.HOUR, 0); cal.set(Calendar.MILLISECOND, 0); for (int i = 0; i < histo.length; i++) { histo[i] = 0; } convLogger.initialize("mich_conabio", databaseName); StringBuilder extraStyle = new StringBuilder(); extraStyle.append("TD.yw { color: rgb(200,200,0); }\n"); extraStyle.append("TD.gr { color: rgb(200,0,200); }\n"); extraStyle.append("TD.bgr { color: rgb(0,255,0); }\n"); extraStyle.append("TD.byw { color: yellow; }\n"); extraStyle.append("TD.df { color: rgb(100,255,200); }\n"); String mapTableName = "maptable"; Statement stmt = null; try { conn = DriverManager.getConnection( "jdbc:mysql://localhost/" + databaseName + "?characterEncoding=UTF-8&autoReconnect=true", "root", "root"); BasicSQLUtils.setDBConnection(conn); int matches = BasicSQLUtils.getCountAsInt("SELECT COUNT(*) FROM maptable"); //tblWriter.log(String.format("Number of records that match - Genus, Species, CollectorNumber, CatalogNumber: "+matches)); mpStmt = conn.prepareStatement("INSERT INTO " + mapTableName + " VALUES (?,?)"); String sqlMain = "SELECT E.IdEjemplar, E.NumeroDeCatalogo, NumeroDeColecta, Grupo.DescripcionGpo AS Colector, " + "NombreLocalidad.NombreOriginal, CategoriaTaxonomica.NombreCategoriaTaxonomica, IF (CategoriaTaxonomica.IdNivel1<7,Nombre.Nombre, " + "IF (CategoriaTaxonomica.IdNivel3 = 0, CONCAT(Nombre_1.Nombre,\" \", Nombre.Nombre),CONCAT(Nombre_2.Nombre, \" \",Nombre_1.Nombre,\" \", " + "Nombre.Nombre))) AS Nombre, Nombre_2.Nombre AS N2, Nombre_1.Nombre AS N1, Nombre.Nombre AS N0, " + "AnioColecta, MesColecta, DiaColecta FROM Grupo " + "INNER JOIN (CategoriaTaxonomica INNER JOIN (NombreLocalidad " + "INNER JOIN (((Nombre INNER JOIN Nombre AS Nombre_1 ON Nombre.IdAscendObligatorio = Nombre_1.IdNombre) " + "INNER JOIN Nombre AS Nombre_2 ON Nombre_1.IdAscendObligatorio = Nombre_2.IdNombre) " + "INNER JOIN Ejemplar E ON Nombre.IdNombre = E.IdNombre) ON NombreLocalidad.IdNombreLocalidad = E.IdNombreLocalidad) " + "ON CategoriaTaxonomica.IdCategoriaTaxonomica = Nombre.IdCategoriaTaxonomica) ON Grupo.IdGrupo = E.IdColector " + "ORDER BY E.NumeroDeCatalogo "; String sql = sqlMain; //if (!doingMapTable) //{ // sql = "SELECT * FROM (" + sqlMain + ") T1 LEFT JOIN maptable ON IdEjemplar = OldID WHERE NewID IS NULL"; //} TableWriter tblWriter = convLogger.getWriter("MichConabio1.html", "Matches Cat No. / Collector No. / Genus / Species", extraStyle.toString()); tblWriter.startTable(); tblWriter.log("<TR><TH COLSPAN=\"7\">Conabio</TH><TH COLSPAN=\"7\">Michigan</TH><TD> </TH></TR>"); tblWriter.logHdr("Col Num", "Cat Num", "Genus", "Species", "Collector", "Locality", "Date Collected", "Col Num", "Cat Num", "Genus", "Species", "Collector", "Locality", "Date Collected", "Score"); fndCnt = 0; numRecs = 0; System.out.println(sql); stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); ResultSet rs = stmt.executeQuery(sql); while (rs.next()) { process(0, rs, tblWriter, doingMapTable); } rs.close(); tblWriter.endTable(); tblWriter.log("<BR>"); tblWriter.log(String.format("Number of records that match: %d of %d records.", fndCnt, numRecs)); tblWriter.log(String.format("Average Score: %5.2f", ((double) totalScore / (double) fndCnt))); tblWriter.log(String.format("Mode Score: %d", getModeScore())); totalScore = 0; sql = "SELECT * FROM (" + sqlMain + ") T1 LEFT JOIN maptable ON IdEjemplar = OldID WHERE NewID IS NULL"; fndCnt = 0; numRecs = 0; tblWriter = convLogger.getWriter("MichConabio2.html", "Matches Cat No. / Collector No. ", extraStyle.toString()); tblWriter.startTable(); tblWriter.log("<TR><TH COLSPAN=\"7\">Conabio</TH><TH COLSPAN=\"7\">Michigan</TH><TD> </TH></TR>"); tblWriter.logHdr("Col Num", "Cat Num", "Genus", "Species", "Collector", "Locality", "Date Collected", "Col Num", "Cat Num", "Genus", "Species", "Collector", "Locality", "Date Collected", "Score"); rs = stmt.executeQuery(sql); while (rs.next()) { process(1, rs, tblWriter, doingMapTable); } rs.close(); tblWriter.endTable(); tblWriter.log("<BR>"); tblWriter.log(String.format("Number of records that match: %d of %d records.", fndCnt, numRecs)); tblWriter.log(String.format("Average Score: %5.2f", ((double) totalScore / (double) fndCnt))); tblWriter.log(String.format("Mode Score: %d", getModeScore())); totalScore = 0; fndCnt = 0; numRecs = 0; tblWriter = convLogger.getWriter("MichConabio3.html", "Matches Collector No. ", extraStyle.toString()); tblWriter.startTable(); tblWriter.log("<TR><TH COLSPAN=\"7\">Conabio</TH><TH COLSPAN=\"7\">Michigan</TH><TD> </TH></TR>"); tblWriter.logHdr("Col Num", "Cat Num", "Genus", "Species", "Collector", "Locality", "Date Collected", "Col Num", "Cat Num", "Genus", "Species", "Collector", "Locality", "Date Collected", "Score"); rs = stmt.executeQuery(sql); while (rs.next()) { process(2, rs, tblWriter, doingMapTable); } rs.close(); tblWriter.endTable(); tblWriter.log("<BR>"); tblWriter.log(String.format("Number of records that match: %d of %d records.", fndCnt, numRecs)); tblWriter.log(String.format("Average Score: %5.2f", ((double) totalScore / (double) fndCnt))); tblWriter.log(String.format("Mode Score: %d", getModeScore())); totalScore = 0; fndCnt = 0; numRecs = 0; tblWriter = convLogger.getWriter("MichConabio4.html", "Matches Cat No. ", extraStyle.toString()); tblWriter.startTable(); tblWriter.log("<TR><TH COLSPAN=\"7\">Conabio</TH><TH COLSPAN=\"7\">Michigan</TH><TD> </TH></TR>"); tblWriter.logHdr("Col Num", "Cat Num", "Genus", "Species", "Collector", "Locality", "Date Collected", "Col Num", "Cat Num", "Genus", "Species", "Collector", "Locality", "Date Collected", "Score"); rs = stmt.executeQuery(sql); while (rs.next()) { process(3, rs, tblWriter, doingMapTable); } rs.close(); tblWriter.endTable(); tblWriter.log("<BR>"); tblWriter.log(String.format("Number of records that match: %d of %d records.", fndCnt, numRecs)); tblWriter.log(String.format("Average Score: %5.2f", ((double) totalScore / (double) fndCnt))); tblWriter.log(String.format("Mode Score: %d", getModeScore())); totalScore = 0; tblWriter.flush(); } catch (Exception ex) { ex.printStackTrace(); } finally { try { stmt.close(); mpStmt.close(); conn.close(); } catch (Exception ex) { ex.printStackTrace(); } } File indexFile = convLogger.closeAll(); try { AttachmentUtils.openURI(indexFile.toURI()); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } //int n = StringUtils.getLevenshteinDistance("guatemaliense", "guatemalense"); //System.out.println(n); // tblWriter.println("<BR>"); // for (int i=0;i<histo.length;i++) // { // if (histo[i] > 0) // { // tblWriter.print(String.format("%3d - ", i)); // for (int x=0;x<histo[i]/2;x++) // { // tblWriter.print('*'); // } // tblWriter.println("<BR>"); // } // } // tblWriter.flush(); }
From source file:org.ambraproject.admin.service.impl.SyndicationServiceImpl.java
@Transactional @SuppressWarnings("unchecked") @Override/*from w ww.ja v a 2 s. c om*/ public List<Syndication> getFailedAndInProgressSyndications(final String journalKey) { Integer numDaysInPast = configuration .getInteger("ambra.virtualJournals." + journalKey + ".syndications.display.numDaysInPast", 30); // The most recent midnight. No need to futz about with exact dates. final Calendar start = Calendar.getInstance(); start.set(Calendar.HOUR, 0); start.set(Calendar.MINUTE, 0); start.set(Calendar.SECOND, 0); start.set(Calendar.MILLISECOND, 0); final Calendar end = (Calendar) start.clone(); // The most recent midnight (last night) start.add(Calendar.DATE, -(numDaysInPast)); end.add(Calendar.DATE, 1); // Include everything that happened today. final Journal journal = journalService.getJournal(journalKey); if (journal == null) { throw new SyndicationException("Could not find journal for journal key: " + journalKey); } return (List<Syndication>) hibernateTemplate.execute(new HibernateCallback() { public Object doInHibernate(Session session) throws HibernateException, SQLException { StringBuilder sql = new StringBuilder(); sql.append("select {s.*} from syndication s ").append("join article a on s.doi = a.doi ") .append("where s.status in ('" + Syndication.STATUS_IN_PROGRESS + "','" + Syndication.STATUS_FAILURE + "')") .append("and s.lastModified between '" + mysqlDateFormat.format(start.getTime()) + "'") .append(" and '" + mysqlDateFormat.format(end.getTime()) + "' and ") .append("a.eIssn = '" + journal.geteIssn() + "'"); return session.createSQLQuery(sql.toString()).addEntity("s", Syndication.class).list(); } }); }
From source file:com.sfs.whichdoctor.beans.AgedDebtorsAnalysisBean.java
/** * Construct the periods for the aged debtors analysis. * * @return the period tree map/*from w w w. jav a 2s . com*/ */ private TreeMap<Integer, AgedDebtorsPeriod> constructPeriods() { TreeMap<Integer, AgedDebtorsPeriod> newPeriods = new TreeMap<Integer, AgedDebtorsPeriod>(); final int hour = 23; final int minute = 59; final int second = 59; String length = this.getPeriodLength(); String unit = "Month"; int calendarField = Calendar.MONTH; int duration = 1; try { if (length.indexOf("d") > 0) { // This is a day period unit = "Day"; calendarField = Calendar.DAY_OF_MONTH; duration = Integer.parseInt(length.substring(0, length.indexOf("d"))); } if (length.indexOf("m") > 0) { // This is a month period unit = "Month"; calendarField = Calendar.MONTH; duration = Integer.parseInt(length.substring(0, length.indexOf("m"))); } if (length.indexOf("y") > 0) { // This is a year period unit = "Year"; calendarField = Calendar.YEAR; duration = Integer.parseInt(length.substring(0, length.indexOf("y"))); } } catch (NumberFormatException nfe) { // An error occurred while parsing the period length, set to defaults unit = "Month"; duration = 1; calendarField = Calendar.MONTH; } for (int i = 0; i < this.getNumberOfPeriods(); i++) { String title = "Current"; if (i > 0) { int x = duration * i; title = String.valueOf(x) + " " + unit; if (x > 1) { title += "s"; } } Calendar start = Calendar.getInstance(); Calendar end = Calendar.getInstance(); start.setTime(getAsAtDate()); start.add(calendarField, -duration * i); start.set(Calendar.HOUR, hour); start.set(Calendar.MINUTE, minute); start.set(Calendar.SECOND, second); end.setTimeInMillis(start.getTimeInMillis()); // Add one second to the end date, then subtract a period of time end.add(Calendar.SECOND, 1); end.add(calendarField, -duration); if (i + 1 == this.getNumberOfPeriods()) { // Add a plus to the end of the title to signify it is the last period title += "+"; // The last period has the lowest possible end date Date lastDate = DataFilter.parseDate("1/1/1900", false); end.setTimeInMillis(lastDate.getTime()); } Date startDate = new Date(start.getTimeInMillis()); Date endDate = new Date(end.getTimeInMillis()); try { newPeriods.put(i, new AgedDebtorsPeriod(i, title, startDate, endDate)); } catch (WhichDoctorBeanException wbe) { logger.error("Error creating aged debtors period", wbe); } } return newPeriods; }