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:cloudnet.weather.data.forecastio.WeatherDataFetcher.java
public void fetchData(String locationData, String city, Calendar start, Calendar end) { try {//from w ww .ja v a2 s . c om URL url; while (start.before(end)) { url = new URL(urlString + locationData + "," + start.getTimeInMillis() / 1000 + "?units=si"); File file = new File("resources/weather/" + city + "/" + start.getTimeInMillis() / 1000 + ".json"); LOGGER.trace("downloading " + start.getTimeInMillis() / 1000); FileUtils.copyURLToFile(url, file); start.add(Calendar.HOUR, 12); } } catch (MalformedURLException e) { LOGGER.error("fetchData", e); } catch (IOException e) { LOGGER.error("fetchData", e); } }
From source file:com.oasis.wolfburg.service.qzSchedule.handler.RsJobNotificationHandler.java
public void handle() { Calendar cal = Calendar.getInstance(); cal.add(Calendar.HOUR, 24); Date notifyDate = cal.getTime(); List<TruckRSJob> jobList = truckRSJobDAO.getNotificationJobs(notifyDate); if (jobList.size() > 0) { notify(jobList);/*from w w w . ja va 2s. c o m*/ } }
From source file:com.discursive.jccook.lang.DateFormatExample.java
public void testRoundedDates() throws Exception { FastDateFormat sdf = DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT; Date now = new Date(); Date nearestHour = DateUtils.round(now, Calendar.HOUR); Date nearestMonth = DateUtils.round(now, Calendar.MONTH); Date nearestYear = DateUtils.round(now, Calendar.YEAR); logger.debug("now: " + sdf.format(now)); logger.debug("round hour: " + sdf.format(nearestHour)); logger.debug("round month: " + sdf.format(nearestMonth)); logger.debug("round year: " + sdf.format(nearestYear)); }
From source file:eionet.gdem.qa.WQCleanerJob.java
/** * Check the job's age and return true if it is possible to delete it. * * @param job//from w ww.j av a 2s . co m * Workqueue job object * @return true if job can be deleted. */ public static boolean canDeleteJob(WorkqueueJob job) { boolean canDelete = false; if (job != null && job.getJobTimestamp() != null && job.getStatus() >= Constants.XQ_READY) { Calendar now = Calendar.getInstance(); int maxAge = Properties.wqJobMaxAge == 0 ? -1 : -Properties.wqJobMaxAge; now.add(Calendar.HOUR, maxAge); Calendar jobCal = Calendar.getInstance(); jobCal.setTime(job.getJobTimestamp()); if (now.after(jobCal)) { canDelete = true; } } return canDelete; }
From source file:org.kuali.coeus.s2sgen.impl.datetime.S2SDateTimeServiceImpl.java
/** * * This method computes the number of months between any 2 given {@link java.sql.Date} objects * * @param dateStart starting date.//from w w w. j av a 2s. co m * @param dateEnd end date. * * @return number of months between the start date and end date. */ @Override public ScaleTwoDecimal getNumberOfMonths(java.util.Date dateStart, java.util.Date dateEnd) { ScaleTwoDecimal monthCount = ScaleTwoDecimal.ZERO; int fullMonthCount = 0; Calendar startDate = Calendar.getInstance(); Calendar endDate = Calendar.getInstance(); startDate.setTime(dateStart); endDate.setTime(dateEnd); startDate.clear(Calendar.HOUR); startDate.clear(Calendar.MINUTE); startDate.clear(Calendar.SECOND); startDate.clear(Calendar.MILLISECOND); endDate.clear(Calendar.HOUR); endDate.clear(Calendar.MINUTE); endDate.clear(Calendar.SECOND); endDate.clear(Calendar.MILLISECOND); if (startDate.after(endDate)) { return ScaleTwoDecimal.ZERO; } int startMonthDays = startDate.getActualMaximum(Calendar.DATE) - startDate.get(Calendar.DATE); startMonthDays++; int startMonthMaxDays = startDate.getActualMaximum(Calendar.DATE); BigDecimal startMonthFraction = BigDecimal.valueOf(startMonthDays).setScale(2, RoundingMode.HALF_UP).divide( BigDecimal.valueOf(startMonthMaxDays).setScale(2, RoundingMode.HALF_UP), RoundingMode.HALF_UP); int endMonthDays = endDate.get(Calendar.DATE); int endMonthMaxDays = endDate.getActualMaximum(Calendar.DATE); BigDecimal endMonthFraction = BigDecimal.valueOf(endMonthDays).setScale(2, RoundingMode.HALF_UP).divide( BigDecimal.valueOf(endMonthMaxDays).setScale(2, RoundingMode.HALF_UP), RoundingMode.HALF_UP); startDate.set(Calendar.DATE, 1); endDate.set(Calendar.DATE, 1); while (startDate.getTimeInMillis() < endDate.getTimeInMillis()) { startDate.set(Calendar.MONTH, startDate.get(Calendar.MONTH) + 1); fullMonthCount++; } fullMonthCount = fullMonthCount - 1; monthCount = monthCount.add(new ScaleTwoDecimal(fullMonthCount)) .add(new ScaleTwoDecimal(startMonthFraction)).add(new ScaleTwoDecimal(endMonthFraction)); return monthCount; }
From source file:ru.org.linux.search.SearchControlController.java
@RequestMapping(value = "/admin/search-reindex", method = RequestMethod.POST, params = "action=all") @PreAuthorize("hasRole('ROLE_ADMIN')") public ModelAndView reindexAll(ServletRequest request) throws Exception { Timestamp startDate = messageDao.getTimeFirstTopic(); Calendar start = Calendar.getInstance(); start.setTime(startDate);//from w ww.j ava 2 s. c om start.set(Calendar.DAY_OF_MONTH, 1); start.set(Calendar.HOUR, 0); start.set(Calendar.MINUTE, 0); for (Calendar i = Calendar.getInstance(); i.after(start); i.add(Calendar.MONTH, -1)) { searchQueueSender.updateMonth(i.get(Calendar.YEAR), i.get(Calendar.MONTH) + 1); } searchQueueSender.updateMonth(1970, 1); return new ModelAndView("action-done", "message", "Scheduled reindex"); }
From source file:Main.java
/** * <p>Checks if two calendar objects represent the same local time.</p> * * <p>This method compares the values of the fields of the two objects. * In addition, both calendars must be the same of the same type.</p> * /*from w w w .ja va 2 s .c om*/ * @param cal1 the first calendar, not altered, not null * @param cal2 the second calendar, not altered, not null * @return true if they represent the same millisecond instant * @throws IllegalArgumentException if either date is <code>null</code> * @since 2.1 */ public static boolean isSameLocalTime(Calendar cal1, Calendar cal2) { if (cal1 == null || cal2 == null) { throw new IllegalArgumentException("The date must not be null"); } return (cal1.get(Calendar.MILLISECOND) == cal2.get(Calendar.MILLISECOND) && cal1.get(Calendar.SECOND) == cal2.get(Calendar.SECOND) && cal1.get(Calendar.MINUTE) == cal2.get(Calendar.MINUTE) && cal1.get(Calendar.HOUR) == cal2.get(Calendar.HOUR) && cal1.get(Calendar.DAY_OF_YEAR) == cal2.get(Calendar.DAY_OF_YEAR) && cal1.get(Calendar.YEAR) == cal2.get(Calendar.YEAR) && cal1.get(Calendar.ERA) == cal2.get(Calendar.ERA) && cal1.getClass() == cal2.getClass()); }
From source file:com.socialsite.dao.hibernate.AnswerDaoTest.java
@Test @Transactional/* w w w . j a va 2 s . com*/ public void testGetAnswers() { // create some students final User user1 = new Student("user1", "password"); saveUsers(user1); final Course course1 = new Course(); course1.setName("test1"); saveCourses(course1); // Questions final Question question1 = new Question("sample Question1", course1, user1); question1.setText("<b>This is a sample Question1</b><em>this is em</em><p>new paragraph"); saveQuestion(question1); // courses course1.addQuestions(question1); saveCourses(course1); // Answers final Answer answer1 = new Answer(question1, user1); answer1.setText("this is a sample answer1"); final Calendar cal = Calendar.getInstance(); cal.add(Calendar.HOUR, 1); // makes sure the answer comes first in the list of anwers answer1.setTime(cal.getTime()); final Answer answer2 = new Answer(question1, user1); answer2.setText("this is a sample answer2"); saveAnswers(answer1, answer2); assertEquals(answer1.getId(), answerDao.getAnswers(question1.getId(), 0, 1).get(0).getId()); assertEquals(2, answerDao.getAnswers(question1.getId(), 0, 2).size()); }
From source file:ro.bmocanu.tests.ws.springws.server.ProductServiceMarshallingPayloadEndpoint.java
@SuppressWarnings("restriction") protected Object invokeInternal(Object request) throws Exception { ObjectFactory objectFactory = new ObjectFactory(); GetProductByIdRequest gpbiRequest = (GetProductByIdRequest) request; long productId = gpbiRequest.getProductId(); Product product = ProductManager.singleInstance.getProductById(productId); XMLGregorianCalendar cal = new com.sun.org.apache.xerces.internal.jaxp.datatype.XMLGregorianCalendarImpl(); Calendar c = Calendar.getInstance(); cal.setTime(c.get(Calendar.HOUR), c.get(Calendar.MINUTE), c.get(Calendar.SECOND)); GetProductByIdResponse gpbiResponse = objectFactory.createGetProductByIdResponse(); ProductType xmlProduct = objectFactory.createProductType(); xmlProduct.setId(product.getId());// w w w .j a v a2 s . co m xmlProduct.setName(product.getName()); xmlProduct.setDescription(product.getDescription()); xmlProduct.setReceived(cal); gpbiResponse.setProduct(xmlProduct); return gpbiResponse; }
From source file:be.fedict.eid.pkira.common.util.FilterHelperBean.java
private Date changeTime(Date date, int hours, int minutes, int seconds) { Calendar calendar = new GregorianCalendar(); calendar.setTime(date);/*ww w. ja v a 2s . c o m*/ calendar.set(Calendar.HOUR, hours); calendar.set(Calendar.MINUTE, minutes); calendar.set(Calendar.SECOND, seconds); return calendar.getTime(); }