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:com.ltmonitor.jt808.service.impl.CommandService.java
/** * ??????//www. j a v a2 s . com */ public final TerminalCommand UpdateStatus(String GpsId, int SN, String status) { try { String hsql = "from TerminalCommand where simNo = ? and SN = ? and CreateDate > ?"; TerminalCommand tc = (TerminalCommand) getBaseDao() .find(hsql, new Object[] { GpsId, SN, DateUtil.getDate(DateUtil.now(), Calendar.HOUR, -1) }); if (tc != null) { tc.setStatus(status); UpdateCommand(tc); } return tc; } catch (Exception ex) { logger.error(ex.getMessage(), ex); } return null; }
From source file:com.digitalpebble.stormcrawler.bolt.FeedParserBolt.java
private List<Outlink> parseFeed(String url, byte[] content, Metadata parentMetadata) throws MalformedURLException { List<Outlink> links = new ArrayList<>(); SyndFeed feed = null;/*from www . j a v a 2s .co m*/ try (ByteArrayInputStream is = new ByteArrayInputStream(content)) { SyndFeedInput input = new SyndFeedInput(); feed = input.build(new InputSource(is)); } catch (Exception e) { LOG.error("Exception parsing feed from DOM {}", url); return links; } URL sURL = new URL(url); List<SyndEntry> entries = feed.getEntries(); for (SyndEntry entry : entries) { String targetURL = entry.getLink(); // build an absolute URL try { targetURL = URLUtil.resolveURL(sURL, targetURL).toExternalForm(); } catch (MalformedURLException e) { LOG.debug("MalformedURLException on {}", targetURL); continue; } targetURL = urlFilters.filter(sURL, parentMetadata, targetURL); if (StringUtils.isBlank(targetURL)) continue; Outlink newLink = new Outlink(targetURL); Metadata targetMD = metadataTransfer.getMetaForOutlink(targetURL, url, parentMetadata); newLink.setMetadata(targetMD); String title = entry.getTitle(); if (StringUtils.isNotBlank(title)) { targetMD.setValue("feed.title", title.trim()); } Date publishedDate = entry.getPublishedDate(); if (publishedDate != null) { // filter based on the published date if (filterHoursSincePub != -1) { Calendar rightNow = Calendar.getInstance(); rightNow.add(Calendar.HOUR, -filterHoursSincePub); if (publishedDate.before(rightNow.getTime())) { LOG.info("{} has a published date {} which is more than {} hours old", targetURL, publishedDate.toString(), filterHoursSincePub); continue; } } targetMD.setValue("feed.publishedDate", publishedDate.toString()); } SyndContent description = entry.getDescription(); if (description != null && StringUtils.isNotBlank(description.getValue())) { targetMD.setValue("feed.description", description.getValue()); } links.add(newLink); } return links; }
From source file:com.etime.ETimeUtils.java
/** * Parse a Punch from a given string. The format is assumed to be "12:00AM". All other calendar fields are set * to the current days value. The day, month, year, timezone and other misc fields are set to the current days value. * * @param punchStr The String to be parsed for the punch * @return the parsed Punch/*from ww w . ja v a2 s . c o m*/ */ private static Punch getPunchFromString(String punchStr) { Punch punch = new Punch(); Calendar calendar; Pattern punchPattern = Pattern.compile("(\\d+):(\\d+)(A|P)M");//Format is "12:00PM" Matcher punchMatcher = punchPattern.matcher(punchStr); if (!punchMatcher.find()) { return null; } int hour = Integer.parseInt(punchMatcher.group(1)); int min = Integer.parseInt(punchMatcher.group(2)); calendar = Calendar.getInstance(); int hour24; if (punchMatcher.group(3).equals("A")) { calendar.set(Calendar.AM_PM, Calendar.AM); calendar.set(Calendar.HOUR, hour); if (hour == 12) { hour24 = 0; } else { hour24 = hour; } } else { calendar.set(Calendar.AM_PM, Calendar.PM); calendar.set(Calendar.HOUR, hour); if (hour != 12) { hour24 = hour + 12; } else { hour24 = hour; } } calendar.set(Calendar.HOUR_OF_DAY, hour24); calendar.set(Calendar.MINUTE, min); calendar.set(Calendar.SECOND, 0); punch.setCalendar(calendar); return punch; }
From source file:org.auraframework.integration.test.http.AuraResourceServletHttpTest.java
/** * GET with If-Modified-Since header from an hour ago, will return 304 if the UID is correct. *///from ww w. j a v a 2s.com @AuraTestLabels("auraSanity") @Test public void testGetWithIfModifiedSinceOldModified() throws Exception { String requestContext = getSimpleContext(Format.JS, true); String url = "/l/" + AuraTextUtil.urlencode(requestContext) + "/app.js"; Calendar stamp = Calendar.getInstance(); stamp.add(Calendar.HOUR, -1); Header[] headers = new Header[] { new BasicHeader(HttpHeaders.IF_MODIFIED_SINCE, new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz").format(stamp.getTime())) }; HttpGet get = obtainGetMethod(url, headers); HttpResponse httpResponse = perform(get); int statusCode = getStatusCode(httpResponse); String response = getResponseBody(httpResponse); get.releaseConnection(); assertEquals(HttpStatus.SC_OK, statusCode); assertNotNull(response); }
From source file:org.openmrs.module.dominicamodule.web.controller.EditPatientDrugsPortletController.java
Date getExpireDateFromDuration(Date date, DrugOrderExtension doe) { Calendar cal = Calendar.getInstance(); cal.setTime(date);/*ww w .jav a2s .com*/ switch (DurationUnit.values()[doe.getDurationUnit()]) { case hours: cal.add(Calendar.HOUR, doe.getDuration()); break; case days: cal.add(Calendar.DAY_OF_YEAR, doe.getDuration()); break; case weeks: cal.add(Calendar.WEEK_OF_YEAR, doe.getDuration()); break; case months: cal.add(Calendar.MONTH, doe.getDuration()); break; case years: cal.add(Calendar.YEAR, doe.getDuration()); break; } return cal.getTime(); }
From source file:com.chortitzer.web.admin.controller.TiemposBean.java
/** * @param selectedRango the selectedRango to set *//*from w ww . j av a2 s. c o m*/ public void setSelectedRango(int selectedRango) { try { this.selectedRango = selectedRango; if (selectedRango != 0) { setFechaHasta(new Date()); switch (selectedRango) { case 1: Calendar cal = Calendar.getInstance(); cal.setTime(new Date()); cal.add(Calendar.MONTH, -1); cal.set(Calendar.DAY_OF_MONTH, 16); cal.set(Calendar.HOUR, 0); cal.set(Calendar.MINUTE, 0); setFechaDesde(cal.getTime()); cal.add(Calendar.MONTH, 1); cal.add(Calendar.MINUTE, -1); setFechaHasta(cal.getTime()); break; case 2: setFechaDesde(DateUtils.truncate(new Date(), Calendar.MONTH)); break; case 3: setFechaDesde(DateUtils.truncate(new Date(), Calendar.YEAR)); break; } } } catch (Exception ex) { LOGGER.error(Thread.currentThread().getStackTrace()[1].getMethodName(), ex); FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "Error!", ex.getMessage())); } }
From source file:de.fhbingen.wbs.wpOverview.tabs.AvailabilityGraph.java
/** * Set the view to YEAR./*from w w w .j a va 2 s . co m*/ */ private void setYearView() { actualStart = (GregorianCalendar) actualDay.clone(); actualStart.set(Calendar.DAY_OF_YEAR, actualDay.getActualMinimum(Calendar.DAY_OF_YEAR)); actualStart.set(Calendar.HOUR, 0); actualStart.set(Calendar.MINUTE, 0); actualStart.add(Calendar.DAY_OF_YEAR, -1); actualEnd = (GregorianCalendar) actualDay.clone(); actualEnd.set(Calendar.DAY_OF_YEAR, actualDay.getActualMaximum(Calendar.DAY_OF_YEAR)); actualEnd.set(Calendar.HOUR, 23); actualEnd.set(Calendar.MINUTE, 59); actualView = YEAR; GregorianCalendar helper = (GregorianCalendar) actualEnd.clone(); helper.add(Calendar.DATE, -1); makeChart(new SimpleDateFormat("yyyy").format(helper.getTime())); }
From source file:CalIcon.java
public void paint(Graphics g) { Calendar myCal = Calendar.getInstance(); StringBuffer sb = new StringBuffer(); sb.append(tf.format(myCal.get(Calendar.HOUR))); sb.append(':'); sb.append(tflz.format(myCal.get(Calendar.MINUTE))); sb.append(':'); sb.append(tflz.format(myCal.get(Calendar.SECOND))); String s = sb.toString();/*from www . ja v a2s. com*/ FontMetrics fm = getFontMetrics(getFont()); int x = (getSize().width - fm.stringWidth(s)) / 2; // System.out.println("Size is " + getSize()); g.drawString(s, x, 10); }
From source file:org.openmrs.module.metadatasharing.resolver.ResolverEngine.java
private boolean ignoreTimezoneEquals(Date date1, Date date2) { if (date1 == null || date2 == null) { return false; }//from w w w. j av a2 s. co m Calendar calendar1 = Calendar.getInstance(); calendar1.setTime(date1); Calendar calendar2 = Calendar.getInstance(); calendar2.setTime(date2); calendar1.set(Calendar.HOUR, 0); calendar2.set(Calendar.HOUR, 0); return calendar1.equals(calendar2); }
From source file:de.hybris.platform.integration.cis.payment.cronjob.DefaultCisFraudReportJob.java
protected Date getLastCronJobEndTime() { final Date endTime = getCisFraudReportDao().findLastFraudReportEndTime(); if (endTime == null) { final Calendar calendar = Calendar.getInstance(); calendar.add(Calendar.HOUR, -23); calendar.add(Calendar.MINUTE, -55); return calendar.getTime(); }/* w w w.jav a 2 s.c o m*/ return endTime; }