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.ozpathway.sw.erms.webapp.action.schedule.ScheduleBean.java
public String saveEntryAction() { if (entry.isAllDay()) { entry.setStartTime(DateUtil.add(DateUtil.getDate(entry.getStartTime()), Calendar.HOUR, this.scheduleSettings.getWorkingStartHour())); entry.setEndTime(DateUtil.add(DateUtil.getDate(entry.getEndTime()), Calendar.HOUR, this.scheduleSettings.getWorkingEndHour())); }//from w ww .j ava2 s .com DocumentManager docManager = (DocumentManager) FacesUtils.getSpringBean("docManager"); docManager.doSaveScheduleEntry(this.entry); if (Long.valueOf(Long.parseLong(this.entry.getExecutorId())).equals(this.getLoginUser().getId())) { this.model.addEntry(entry); this.model.refresh(); } return "success"; }
From source file:edu.depaul.armada.dao.ContainerDaoHibernate.java
@Override public void deleteOldData(int interval) { Query query = sessionFactory.getCurrentSession() .createQuery("delete from Container c where c.timestamp <= :timestamp"); Calendar cal = Calendar.getInstance(); cal.add(Calendar.HOUR, interval * -1); query.setTimestamp("timestamp", new Timestamp(cal.getTimeInMillis())); query.executeUpdate();//from www. j av a2 s. co m }
From source file:ezbake.data.elastic.ElasticClientTest.java
@Before public void setup() throws IOException { esSetup.execute(EsSetup.deleteAll()); client = new ElasticClient(esSetup.client(), APPLICATION_NAME, true, 1); setMappingForTest();// w ww . j a va2 s . com final Calendar visit = new GregorianCalendar(); Visibility aVis = new Visibility().setFormalVisibility("A"); // Jefferson Memorial jeffersonMemorial = new PlaceOfInterest(); jeffersonMemorial.setTitle("Jefferson Memorial"); jeffersonMemorial.setComments( "The Thomas Jefferson Memorial is a presidential monument in Washington, D.C., dedicated to Thomas " + "Jefferson, (17431826), one of the most important of the American \"Founding Fathers\" as " + "the main drafter and writer of the \"Declaration of Independence\", member of the " + "Continental Congress, Governor of the newly independent Commonwealth of Virginia, American" + " minister to King Louis XVI and the Kingdom of France, first U.S. Secretary of State under" + " the first President George Washington, the second Vice President of the United States " + "under second President John Adams, and also the third President of the United States, " + "(18011809)."); jeffersonMemorial.setLocation(new Location(38.889468, -77.03524)); jeffersonMemorial.setRating(92); jeffersonMemorial.setVisit(visit.getTime()); jeffersonMemorial.setTags(Sets.newHashSet("jefferson", "memorial", "dc")); String jeffersonMemorialJson = gson.toJson(jeffersonMemorial); jeffersonMemorialDoc = EzElasticTestUtils.generateDocument(TEST_TYPE, jeffersonMemorialJson, aVis); jeffersonMemorialDocWithVis = EzElasticTestUtils.generateDocument(TEST_TYPE, jeffersonMemorialJson, new Visibility().setFormalVisibility("A&B&(C|D)")); // Columbia columbia = new PlaceOfInterest(); columbia.setTitle("Columbia"); columbia.setComments( "Columbia is a planned community comprising 10 self-contained villages, located in Howard " + "County, Marylandthe second wealthiest county in the United States, according to " + "2013 U.S. Census Bureau figures."); columbia.setLocation(new Location(39.182786, -76.808853)); columbia.setRating(92); visit.add(Calendar.HOUR, -5); columbia.setVisit(visit.getTime()); columbia.setTags(Sets.newHashSet("columbia", "community", "md")); String columbiaJson = gson.toJson(columbia); columbiaDoc = EzElasticTestUtils.generateDocument(TEST_TYPE, columbiaJson, aVis); columbiaDocWithVis = EzElasticTestUtils.generateDocument(TEST_TYPE, columbiaJson, new Visibility().setFormalVisibility("A&B&E")); //Lincoln Memorial lincolnMemorial = new PlaceOfInterest(); lincolnMemorial.setTitle("Lincoln Memorial"); lincolnMemorial.setComments( "The Lincoln Memorial is an American national monument built to honor the 16th President of the " + "United States, Abraham Lincoln. Made of white stone."); lincolnMemorial.setLocation(new Location(38.888481, -77.051518)); lincolnMemorial.setRating(2); visit.add(Calendar.HOUR, -2); lincolnMemorial.setVisit(visit.getTime()); lincolnMemorial.setTags(Sets.newHashSet("lincoln", "memorial", "dc")); String lincolnMemorialJson = gson.toJson(lincolnMemorial); lincolnMemorialDoc = EzElasticTestUtils.generateDocument(TEST_TYPE, lincolnMemorialJson, aVis); lincolnMemorialDocWithVis = EzElasticTestUtils.generateDocument(TEST_TYPE, lincolnMemorialJson, new Visibility().setFormalVisibility("C|E")); // White House whiteHouse = new PlaceOfInterest(); whiteHouse.setTitle("White House"); whiteHouse.setComments( "The home of the president of the US located at 1600 Pennsylvania Ave. Since 1800 it has " + "been the home of every US president."); whiteHouse.setTags(Sets.newHashSet("dc", "white", "monument")); whiteHouse.setLocation(new Location(38.8977, -77.0365)); whiteHouse.setRating(23); visit.add(Calendar.DAY_OF_MONTH, -3); whiteHouse.setVisit(visit.getTime()); String whiteHouseJson = gson.toJson(whiteHouse); whiteHouseDoc = EzElasticTestUtils.generateDocument(TEST_TYPE, whiteHouseJson, aVis); whiteHouseDocWithVis = EzElasticTestUtils.generateDocument(TEST_TYPE, whiteHouseJson, new Visibility().setFormalVisibility("A&(B|E)")); populateWithTestDocs(); }
From source file:cn.mljia.common.notify.utils.DateUtils.java
/** * hour ??// ww w . j a v a 2s . c o m * * @param date * @param hour * @return */ public static Date addHour(Date date, int hour) { Calendar calendar = Calendar.getInstance(); calendar.setTime(date); calendar.add(Calendar.HOUR, hour); return calendar.getTime(); }
From source file:com.inmobi.messaging.consumer.hadoop.TestAbstractHadoopConsumer.java
public void testConsumerWithFutureStartTime() throws Exception { ClientConfig config = loadConfig();/*w ww. j av a 2 s . c o m*/ config.set(HadoopConsumerConfig.rootDirsConfig, rootDirs[0].toString()); Date absoluteStartTime = DatabusStreamWaitingReader.getDateFromStreamDir(rootDirs[0], finalPaths[0][1]); // created a future time stamp Calendar cal = new GregorianCalendar(); cal.setTime(absoluteStartTime); cal.add(Calendar.HOUR, 2); config.set(MessageConsumerFactory.ABSOLUTE_START_TIME, AbstractMessageConsumer.minDirFormat.get().format(cal.getTime())); ConsumerUtil.testConsumerWithFutureStartTime(config); }
From source file:com.rockagen.commons.util.CommUtil.java
/** * Return the next month's date and time 00:00:00 start date * * @param date Date/*from w ww . j a v a2 s .co m*/ * @return next month begin */ public static Date nextMonthBegin(Date date) { Calendar cal = getCalendar(date); cal.set(Calendar.DAY_OF_MONTH, 1); // next month's am O0:00:00 cal.add(Calendar.MONTH, 1); cal.set(Calendar.AM_PM, Calendar.AM); cal.set(Calendar.HOUR, 0); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); return cal.getTime(); }
From source file:CalendarUtils.java
/** * Parses strings the way that CVS supports it... very human readable *//* w ww. ja v a2s . c o m*/ public static Calendar parse(String original, Locale locale) { //Get the symbol names DateFormatSymbols symbols = new DateFormatSymbols(locale); //Prep the string to parse String value = original.toLowerCase().trim(); //Get the current date/time Calendar now = Calendar.getInstance(); if (value.endsWith(" ago")) { //If this was a date that was "ago" the current time... //Strip out the ' ago' part value = value.substring(0, value.length() - 4); //Split the value and unit int start = value.indexOf(" "); if (start < 0) { throw new RuntimeException("Could not find space in between value and unit"); } String unit = value.substring(start + 1); value = value.substring(0, start); //We support "a week", so we need to parse the value as "a" int val = 0; if (value.equals("a") || value.equals("an")) { val = 1; } else { val = Integer.parseInt(value); } //Determine the unit if (unit.equals("milliseconds") || unit.equals("millisecond")) { now.add(Calendar.MILLISECOND, -val); } else if (unit.equals("seconds") || unit.equals("second")) { now.add(Calendar.SECOND, -val); } else if (unit.equals("minutes") || unit.equals("minute")) { now.add(Calendar.MINUTE, -val); } else if (unit.equals("hours") || unit.equals("hour")) { now.add(Calendar.HOUR, -val); } else if (unit.equals("days") || unit.equals("day")) { now.add(Calendar.DATE, -val); } else if (unit.equals("weeks") || unit.equals("week")) { now.add(Calendar.DATE, -val * 7); } else if (unit.equals("fortnights") || unit.equals("fortnight")) { now.add(Calendar.DATE, -val * 14); } else if (unit.equals("months") || unit.equals("month")) { now.add(Calendar.MONTH, -val); } else if (unit.equals("years") || unit.equals("year")) { now.add(Calendar.YEAR, -val); } else { throw new RuntimeException("We do not understand that many units ago"); } return now; } else if (value.startsWith("last ")) { //If this was the last time a certain field was met //Strip out the 'last ' part value = value.substring(5); //Get the current date/time String[] strings = symbols.getWeekdays(); for (int i = 0; i < strings.length; i++) { if (value.equalsIgnoreCase(strings[i])) { //How many days after Sunday int daysAgo = now.get(Calendar.DAY_OF_WEEK) - i; if (daysAgo <= 0) { daysAgo += 7; } now.add(Calendar.DATE, -daysAgo); return now; } } strings = symbols.getMonths(); for (int i = 0; i < strings.length; i++) { if (value.equalsIgnoreCase(strings[i])) { //How many days after January int monthsAgo = now.get(Calendar.MONTH) - i; if (monthsAgo <= 0) { monthsAgo += 12; } now.add(Calendar.MONTH, -monthsAgo); return now; } } if (value.equals("week")) { now.add(Calendar.DATE, -7); return now; } } else if (value.equals("yesterday")) { now.add(Calendar.DATE, -1); return now; } else if (value.equals("tomorrow")) { now.add(Calendar.DATE, 1); return now; } //Try to parse the date a number of different ways for (int i = 0; i < dateFormats.length; i++) { try { Date datetime = dateFormats[i].parse(original); Calendar cal = Calendar.getInstance(); cal.setTime(datetime); return cal; } catch (ParseException pe) { //we ignore this and just keep trying } } throw new RuntimeException("Unable to parse '" + original + "'."); }
From source file:com.marklogic.client.functionaltest.TestJacksonDateTimeFormat.java
public void validateSpecialArtifactDateTime(SpecialArtifactDateTime artifact, String artifactName, long longId, Calendar datetime) {/*from ww w .j a va 2s. c o m*/ System.out.println("Argumnt : " + datetime.toString()); System.out.println("Jackson POJO : " + artifact.getExpiryDate().toString()); assertNotNull("Artifact object should never be Null", artifact); assertNotNull("Id should never be Null", artifact.id); assertEquals("Id of the object is ", longId, artifact.getId()); assertEquals("Name of the object is ", artifactName, artifact.getName()); assertEquals("Inventory of the object is ", 1000, artifact.getInventory()); assertEquals("Company name of the object is ", artifactName, artifact.getManufacturer().getName()); assertEquals("Web site of the object is ", "http://www.acme.com", artifact.getManufacturer().getWebsite()); //Validate the calendar object's field, instead of object or string comparisions. assertEquals("Expiry date: MONTH ", datetime.get(Calendar.MONTH), artifact.getExpiryDate().get(Calendar.MONTH)); assertEquals("Expiry date: DAY_OF_MONTH ", datetime.get(Calendar.DAY_OF_MONTH), artifact.getExpiryDate().get(Calendar.DAY_OF_MONTH)); assertEquals("Expiry date: YEAR ", datetime.get(Calendar.YEAR), artifact.getExpiryDate().get(Calendar.YEAR)); assertEquals("Expiry date: HOUR ", datetime.get(Calendar.HOUR), artifact.getExpiryDate().get(Calendar.HOUR)); assertEquals("Expiry date: MINUTE ", datetime.get(Calendar.MINUTE), artifact.getExpiryDate().get(Calendar.MINUTE)); assertEquals("Expiry date: SECOND ", datetime.get(Calendar.SECOND), artifact.getExpiryDate().get(Calendar.SECOND)); assertEquals(-87.966, artifact.getManufacturer().getLongitude(), 0.00); assertEquals(41.998, artifact.getManufacturer().getLatitude(), 0.00); }
From source file:net.servicestack.client.Utils.java
public static Date ParseManual(String dateTimeStr) { if (dateTimeStr == null || dateTimeStr.length() < "yyyy-MM-dd".length()) return null; if (dateTimeStr.endsWith("Z")) dateTimeStr = dateTimeStr.substring(0, dateTimeStr.length() - 1); String[] parts = dateTimeStr.split("T"); if (parts.length == 1) parts = Utils.splitOnFirst(dateTimeStr, ' '); String[] dateParts = parts[0].split("-"); int hh = 0, min = 0, ss = 0, ms = 0; double subMs = 0; int offsetMultiplier = 0; if (parts.length == 1) { return new Date(Utils.tryParseInt(dateParts[0]) - 1900, Utils.tryParseInt(dateParts[1]) - 1, Utils.tryParseInt(dateParts[2]), 0, 0, 0); } else if (parts.length == 2) { String[] timeStringParts = parts[1].split("\\+"); if (timeStringParts.length == 2) { offsetMultiplier = -1;/* ww w . ja v a2s .co m*/ } else { timeStringParts = parts[1].split("-"); if (timeStringParts.length == 2) { offsetMultiplier = 1; } } String timeOffset = timeStringParts.length == 2 ? timeStringParts[1] : null; String[] timeParts = timeStringParts[0].split(":"); if (timeParts.length == 3) { Integer val = null; if ((val = Utils.tryParseInt(timeParts[0])) != null) hh = val; if ((val = Utils.tryParseInt(timeParts[1])) != null) min = val; String[] secParts = timeParts[2].split("\\."); if ((val = Utils.tryParseInt(secParts[0])) != null) ss = val; if (secParts.length == 2) { String msStr = String.format("%03d", Utils.tryParseInt(secParts[1])); ms = Utils.tryParseInt(msStr.substring(0, 3)); if (msStr.length() > 3) { String subMsStr = msStr.substring(3); // subMs = Utils.tryParseDouble(subMsStr) / Math.pow(10, subMsStr.length()); } } } Date dateTime = new Date(Utils.tryParseInt(dateParts[0]) - 1900, Utils.tryParseInt(dateParts[1]) - 1, Utils.tryParseInt(dateParts[2]), hh, min, ss); Calendar cal = Calendar.getInstance(); cal.setTime(dateTime); if (ms > 0) { cal.add(Calendar.MILLISECOND, ms); } // if (subMs != 0) // dateTime=dateTime.AddMilliseconds(subMs); //Doesn't support sub millis if (offsetMultiplier != 0 && timeOffset != null) { timeParts = timeOffset.split(":"); if (timeParts.length == 2) { hh = Utils.tryParseInt(timeParts[0]); min = Utils.tryParseInt(timeParts[1]); } else { hh = Utils.tryParseInt(timeOffset.substring(0, 2)); min = Utils.tryParseInt(timeOffset.substring(2)); } cal.add(Calendar.HOUR, offsetMultiplier * hh); cal.add(Calendar.MINUTE, offsetMultiplier * min); } dateTime = cal.getTime(); return dateTime; } return null; }
From source file:de.feanor.yeoldemensa.data.MensaFactory.java
/** * Returns the Date for next Saturday midnight. Used for valiTo in Mensa. * /*from w w w. ja v a 2 s .c om*/ * @return Date of next Saturday */ private static Date getNextSaturday() { Calendar calendar = Calendar.getInstance(); int weekday = calendar.get(Calendar.DAY_OF_WEEK); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.HOUR, 0); // TODO: Better solved with locales probably if (weekday == Calendar.SATURDAY) { calendar.add(Calendar.DAY_OF_MONTH, 7); return calendar.getTime(); } else if (weekday == Calendar.SUNDAY) { calendar.add(Calendar.DAY_OF_MONTH, 6); return calendar.getTime(); } else { calendar.add(Calendar.DAY_OF_MONTH, Calendar.SATURDAY - weekday); } return calendar.getTime(); }