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:org.hephaestus.fixedformat.impl.TestRecordFactoryBase.java
public void testDetail1Scan() { Object vo = recordFactory.createRecord(DETAIL_RECORD_1); assertNotNull(vo);/*from w w w. j a v a 2s . c o m*/ assertTrue(vo instanceof TstDetailRecord); TstDetailRecord tdr = (TstDetailRecord) vo; assertEquals(2L, tdr.getRecordType()); assertEquals("Item 1", tdr.getDescription()); assertEquals(303L, tdr.getAmount().longValue()); Date dt = tdr.getDate(); Calendar cal = Calendar.getInstance(); cal.setTime(dt); assertEquals(Calendar.AUGUST, cal.get(Calendar.MONTH)); assertEquals(31, cal.get(Calendar.DAY_OF_MONTH)); dt = tdr.getTime(); cal = Calendar.getInstance(); cal.setTime(dt); assertEquals(23, cal.get(Calendar.HOUR_OF_DAY)); assertEquals(33, cal.get(Calendar.MINUTE)); }
From source file:TimeLib.java
/** * Based on code posted at//from ww w . ja va 2 s . c o m * http://forum.java.sun.com/thread.jspa?threadID=488676&messageID=2292012 */ private static int estimateUnitsBetween(long t0, long t1, int field) { long d = t1 - t0; switch (field) { case Calendar.MILLISECOND: return (int) d; // this could be very inaccurate. TODO: use long instead of int? case Calendar.SECOND: return (int) (d / SECOND_MILLIS + .5); case Calendar.MINUTE: return (int) (d / MINUTE_MILLIS + .5); case Calendar.HOUR_OF_DAY: case Calendar.HOUR: return (int) (d / HOUR_MILLIS + .5); case Calendar.DAY_OF_WEEK_IN_MONTH: case Calendar.DAY_OF_MONTH: // case Calendar.DATE : // codes to same int as DAY_OF_MONTH return (int) (d / DAY_MILLIS + .5); case Calendar.WEEK_OF_YEAR: return (int) (d / WEEK_MILLIS + .5); case Calendar.MONTH: return (int) (d / MONTH_MILLIS + .5); case Calendar.YEAR: return (int) (d / YEAR_MILLIS + .5); case DECADE: return (int) (d / DECADE_MILLIS + .5); case CENTURY: return (int) (d / CENTURY_MILLIS + .5); case MILLENIUM: return (int) (d / MILLENIUM_MILLIS + .5); default: return 0; } }
From source file:dreamboxdataservice.DreamboxChannelHandler.java
@Override public void endElement(String uri, String localName, String qName) throws SAXException { if (qName.equals("e2event")) { try {/* w w w .j a v a2 s .c o m*/ Calendar cal = Calendar.getInstance(); cal.setTime(new java.util.Date(Long.parseLong(mCurrentEvent.get("e2eventstart")) * 1000)); Date programDate = new Date(cal); MutableProgram prog = new MutableProgram(mChannel, programDate, cal.get(Calendar.HOUR_OF_DAY), cal.get(Calendar.MINUTE), true); prog.setTitle(mCurrentEvent.get("e2eventtitle")); prog.setDescription(mCurrentEvent.get("e2eventdescriptionextended")); String shortDesc = mCurrentEvent.get("e2eventdescription"); if (shortDesc.equals(prog.getTitle())) { shortDesc = ""; } if (StringUtils.isEmpty(shortDesc)) { shortDesc = mCurrentEvent.get("e2eventdescriptionextended"); } shortDesc = MutableProgram.generateShortInfoFromDescription(shortDesc); prog.setShortInfo(shortDesc); prog.setLength(Integer.parseInt(mCurrentEvent.get("e2eventduration")) / 60); prog.setProgramLoadingIsComplete(); MutableChannelDayProgram mutDayProg = getMutableDayProgram(programDate); mutDayProg.addProgram(prog); } catch (NumberFormatException e) { e.printStackTrace(); } } else if (qName.equals("e2eventlist")) { storeDayPrograms(mUpdateManager); } else { mCurrentEvent.put(qName, mCharacters.toString()); } }
From source file:erpsystem.chart.Charts.java
private static String toString(Calendar calendar) { String result = ""; int y = calendar.get(Calendar.YEAR); int m = calendar.get(Calendar.MONTH) + 1; int d = calendar.get(Calendar.DAY_OF_MONTH); int h = calendar.get(Calendar.HOUR_OF_DAY); int mm = calendar.get(Calendar.MINUTE); int s = calendar.get(Calendar.SECOND); result += d + "/" + m + "/" + y + ":" + h + "/" + mm + "/" + s; return result; }
From source file:com.lfv.yada.net.server.ServerLogger.java
public synchronized void resume(int h, int m, int s) { // Create a calendar Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("UTC")); cal.setTimeInMillis(System.currentTimeMillis()); cal.set(Calendar.HOUR_OF_DAY, h); cal.set(Calendar.MINUTE, m);/* w w w .j a va 2 s . c o m*/ cal.set(Calendar.SECOND, s); resumeTime = cal.getTimeInMillis(); startTime = System.currentTimeMillis(); suspendTime = 0; }
From source file:adalid.commons.util.TimeUtils.java
public static synchronized Date getDate(java.util.Date date) { if (date == null) { return currentDate(); }//from w w w. j a v a2s . c o m Calendar c = Calendar.getInstance(); c.setTimeInMillis(date.getTime()); c.set(Calendar.HOUR_OF_DAY, 0); c.set(Calendar.MINUTE, 0); c.set(Calendar.SECOND, 0); c.set(Calendar.MILLISECOND, 0); return new Date(c.getTimeInMillis()); }
From source file:ru.org.linux.spring.DelIPController.java
/** * ? ip // w w w . j av a2s.c o m * @param request http ? (? ? ?) * @param reason ? * @param ip ip ? * @param time ? ? (hour, day, 3day) * @return ? ? ? * @throws Exception - ??? */ @RequestMapping(value = "/delip.jsp", method = RequestMethod.POST) public ModelAndView delIp(HttpServletRequest request, @RequestParam("reason") String reason, @RequestParam("ip") String ip, @RequestParam("time") String time) throws Exception { Map<String, Object> params = new HashMap<>(); Template tmpl = Template.getTemplate(request); if (!tmpl.isModeratorSession()) { throw new AccessViolationException("Not moderator"); } Calendar calendar = Calendar.getInstance(); calendar.setTime(new Date()); if ("hour".equals(time)) { calendar.add(Calendar.HOUR_OF_DAY, -1); } else if ("day".equals(time)) { calendar.add(Calendar.DAY_OF_MONTH, -1); } else if ("3day".equals(time)) { calendar.add(Calendar.DAY_OF_MONTH, -3); } else { throw new UserErrorException("Invalid count"); } Timestamp ts = new Timestamp(calendar.getTimeInMillis()); params.put("message", "? ?? ? " + ts.toString() + " ? IP " + ip + "<br>"); User moderator = tmpl.getCurrentUser(); DeleteCommentResult deleteResult = commentService.deleteCommentsByIPAddress(ip, ts, moderator, reason); params.put("topics", deleteResult.getDeletedTopicIds().size()); // - params.put("deleted", deleteResult.getDeleteInfo()); for (int topicId : deleteResult.getDeletedTopicIds()) { searchQueueSender.updateMessage(topicId, true); } searchQueueSender.updateComment(deleteResult.getDeletedCommentIds()); return new ModelAndView("delip", params); }
From source file:DateUtils.java
/** * Get ISO 8601 timestamp./*w ww . jav a 2s . c o m*/ */ public final static String getISO8601Date(long millis) { StringBuffer sb = new StringBuffer(19); Calendar cal = new GregorianCalendar(); cal.setTimeInMillis(millis); // year sb.append(cal.get(Calendar.YEAR)); // month sb.append('-'); int month = cal.get(Calendar.MONTH) + 1; if (month < 10) { sb.append('0'); } sb.append(month); // date sb.append('-'); int date = cal.get(Calendar.DATE); if (date < 10) { sb.append('0'); } sb.append(date); // hour sb.append('T'); int hour = cal.get(Calendar.HOUR_OF_DAY); if (hour < 10) { sb.append('0'); } sb.append(hour); // minute sb.append(':'); int min = cal.get(Calendar.MINUTE); if (min < 10) { sb.append('0'); } sb.append(min); // second sb.append(':'); int sec = cal.get(Calendar.SECOND); if (sec < 10) { sb.append('0'); } sb.append(sec); return sb.toString(); }
From source file:org.openmeetings.app.remote.ChatService.java
private String parseDateAsTimeString() { Calendar cal = Calendar.getInstance(); int h = cal.get(Calendar.HOUR_OF_DAY); int m = cal.get(Calendar.MINUTE); String str_h, str_m;// w w w .j a v a 2s . c o m if (h < 10) str_h = "0" + Integer.toString(h); else str_h = Integer.toString(h); if (m < 10) str_m = "0" + Integer.toString(m); else str_m = Integer.toString(m); return str_h + ':' + str_m; }
From source file:com.spoiledmilk.cykelsuperstier.break_rote.LocalTrainData.java
public static ArrayList<ITransportationInfo> getNext3Arrivals(String fromStation, String toStation, String line, Context context) {/*from w w w. j av a 2 s . c o m*/ ArrayList<ITransportationInfo> ret = new ArrayList<ITransportationInfo>(); String lineNumber = line.split(" ")[0]; String jsonStr = Util.stringFromJsonAssets(context, "stations/local-trains-timetable.json"); JsonNode root = Util.stringToJsonNode(jsonStr); JsonNode lines = root.get("local-trains"); for (int i = 0; i < lines.size(); i++) { if (lines.get(i).get("line").asText().trim().equalsIgnoreCase(lineNumber.trim())) { JsonNode stationsArray = lines.get(i).get("stations"); int direction = -1, index1 = -1, index2 = -1; for (int j = 0; j < stationsArray.size(); j++) { if (stationsArray.get(j).asText().trim().equalsIgnoreCase(fromStation.trim()) && index1 < 0) { index1 = j; if (direction < 0) direction = DEPARTURE; else break; } if (stationsArray.get(j).asText().trim().equalsIgnoreCase(toStation.trim()) && index2 < 0) { index2 = j; if (direction < 0) direction = ARRIVAL; else break; } } if (direction < 0 || index1 < 0 || index2 < 0) break; JsonNode timetableNodeContainer = direction == DEPARTURE ? lines.get(i).get("departure") : lines.get(i).get("arrival"); Calendar calendar = Calendar.getInstance(); int day = calendar.get(Calendar.DAY_OF_WEEK); if (day == 1) day = 6; else day -= 2; int hour = calendar.get(Calendar.HOUR_OF_DAY); int minute = calendar.get(Calendar.MINUTE); JsonNode timeTableNode; if (day >= 0 && day <= 4) { timeTableNode = timetableNodeContainer.get("weekdays"); if (timeTableNode != null) getTimesForWeekdays(hour, minute, ret, timeTableNode, index1, index2, stationsArray.size()); } else if (day == 5) { // Saturday timeTableNode = timetableNodeContainer.get("weekend").get("saturday"); if (timeTableNode != null) { JsonNode dataNodeArray = timetableNodeContainer.get("weekend").get("data-table"); getTimesForWeekend(hour, minute, ret, timeTableNode, index1, index2, stationsArray.size(), dataNodeArray); } } else { // Saturday timeTableNode = timetableNodeContainer.get("weekend").get("sunday"); if (timeTableNode != null) { JsonNode dataNodeArray = timetableNodeContainer.get("weekend").get("data-table"); getTimesForWeekend(hour, minute, ret, timeTableNode, index1, index2, stationsArray.size(), dataNodeArray); } } if (timeTableNode == null) break; break; } } return ret; }