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:es.tekniker.framework.ktek.util.Utils.java
public static long getTimeinMillis4TimeGMT(int hours, int minutes, int seconds) { Calendar c = getCalendarGMT(); System.out.println("current: " + c.getTime()); c.set(Calendar.HOUR_OF_DAY, hours); c.set(Calendar.MINUTE, minutes); c.set(Calendar.SECOND, seconds); System.out.println("GMT Time: " + c.getTime()); long timeinmillis = c.getTimeInMillis(); System.out.println(" system time in millis " + timeinmillis); return timeinmillis; }
From source file:com.aw.core.db.DbUtil.java
public boolean hasOnlyDateInfo(Date date) { Calendar cal = new GregorianCalendar(); cal.setTime(date);//from ww w . ja va 2s . c o m if (cal.get(Calendar.HOUR_OF_DAY) != 0) return false; if (cal.get(Calendar.MINUTE) != 0) return false; if (cal.get(Calendar.SECOND) != 0) return false; if (cal.get(Calendar.MILLISECOND) != 0) return false; return true; }
From source file:net.kamhon.ieagle.util.DateUtil.java
/** * add time to date./*from w ww . j a va2s .c o m*/ * * @param date * @param time * @return */ public static Date addTime(Date date, Time time) { Calendar calendar = setTime(date); calendar.add(Calendar.SECOND, time.getSecond()); calendar.add(Calendar.MINUTE, time.getMinute()); calendar.add(Calendar.HOUR_OF_DAY, time.getHour()); return calendar.getTime(); }
From source file:facebook4j.internal.util.z_F4JInternalStringUtilTest.java
@Test public void formatISO8601Datetime() throws Exception { Calendar cal = Calendar.getInstance(); cal.set(Calendar.YEAR, 2012); cal.set(Calendar.MONTH, 5);/*from ww w. j ava 2s . co m*/ cal.set(Calendar.DAY_OF_MONTH, 15); cal.set(Calendar.HOUR_OF_DAY, 16); cal.set(Calendar.MINUTE, 17); cal.set(Calendar.SECOND, 18); cal.set(Calendar.MILLISECOND, 0); cal.setTimeZone(TimeZone.getTimeZone("JST")); String actual1 = z_F4JInternalStringUtil.formatISO8601Datetime(cal); assertThat(actual1, is("2012-06-15T16:17:18+0900")); cal.setTimeZone(TimeZone.getTimeZone("UTC")); String actual2 = z_F4JInternalStringUtil.formatISO8601Datetime(cal); assertThat(actual2, is("2012-06-15T07:17:18+0000")); //16-9=7 JSONObject json = new JSONObject( "{\"datetime1\": \"" + actual1 + "\", \"datetime2\": \"" + actual2 + "\"}"); Date d1 = z_F4JInternalParseUtil.getISO8601Datetime("datetime1", json); Date d2 = z_F4JInternalParseUtil.getISO8601Datetime("datetime2", json); assertThat(d1, is(d2)); }
From source file:TimeUtil.java
public static long dateFormat(short weekMins) { long dateMillis = System.currentTimeMillis(); synchronized (statFmtCal) { statFmtCal.setTime(new Date(dateMillis)); // get the day of the week int nowDay = statFmtCal.get(Calendar.DAY_OF_WEEK) - 1; // get day of the week of stat time int statDay = weekMins / 1440; if (nowDay > statDay) { dateMillis -= (nowDay - statDay) * 1440 * 60 * 1000; } else if (nowDay < statDay) { dateMillis += (statDay - nowDay) * 1440 * 60 * 1000; }//from ww w .ja v a 2 s.c o m // now get the hour of the day int nowHour = statFmtCal.get(Calendar.HOUR_OF_DAY); int statHour = (weekMins % 1440) / 60; if (nowHour > statHour) { dateMillis -= (nowHour - statHour) * 60 * 60 * 1000; } else if (nowHour < statHour) { dateMillis += (statHour - nowHour) * 60 * 60 * 1000; } // finally minutes int nowMins = statFmtCal.get(Calendar.MINUTE); int statMins = (weekMins % 1440) % 60; if (nowMins > statMins) { dateMillis -= (nowMins - statMins) * 60 * 1000; } else if (nowMins < statMins) { dateMillis += (statMins - nowMins) * 60 * 1000; } } return dateMillis; }
From source file:Main.java
private static String getCurrentTime() { Calendar calendar = Calendar.getInstance(); String strTime = String.format("%4d-%02d-%02d %02d:%02d:%02d", calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH) + 1, calendar.get(Calendar.DAY_OF_MONTH), calendar.get(Calendar.HOUR_OF_DAY), calendar.get(Calendar.MINUTE), calendar.get(Calendar.SECOND)); return strTime; }
From source file:com.liusoft.dlog4j.util.DateUtils.java
/** * ??//from www .j a va 2 s . c o m * @param year * @param month * @param date * @return */ public static Calendar getDateBegin(int year, int month, int date) { Calendar begin_time = Calendar.getInstance(); begin_time.set(Calendar.YEAR, year); begin_time.set(Calendar.MONTH, month - 1); begin_time.set(Calendar.DATE, date); begin_time.set(Calendar.HOUR_OF_DAY, 0); begin_time.set(Calendar.MINUTE, 0); begin_time.set(Calendar.SECOND, 0); begin_time.set(Calendar.MILLISECOND, 0); return begin_time; }
From source file:DateParser.java
private static Calendar getCalendar(String isodate) { // YYYY-MM-DDThh:mm:ss.sTZD StringTokenizer st = new StringTokenizer(isodate, "-T:.+Z", true); Calendar calendar = new GregorianCalendar(TimeZone.getTimeZone("UTC")); calendar.clear();//from w w w . j a va 2s. co m try { // Year if (st.hasMoreTokens()) { int year = Integer.parseInt(st.nextToken()); calendar.set(Calendar.YEAR, year); } else { return calendar; } // Month if (check(st, "-") && (st.hasMoreTokens())) { int month = Integer.parseInt(st.nextToken()) - 1; calendar.set(Calendar.MONTH, month); } else { return calendar; } // Day if (check(st, "-") && (st.hasMoreTokens())) { int day = Integer.parseInt(st.nextToken()); calendar.set(Calendar.DAY_OF_MONTH, day); } else { return calendar; } // Hour if (check(st, "T") && (st.hasMoreTokens())) { int hour = Integer.parseInt(st.nextToken()); calendar.set(Calendar.HOUR_OF_DAY, hour); } else { calendar.set(Calendar.HOUR_OF_DAY, 0); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.SECOND, 0); calendar.set(Calendar.MILLISECOND, 0); return calendar; } // Minutes if (check(st, ":") && (st.hasMoreTokens())) { int minutes = Integer.parseInt(st.nextToken()); calendar.set(Calendar.MINUTE, minutes); } else { calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.SECOND, 0); calendar.set(Calendar.MILLISECOND, 0); return calendar; } // // Not mandatory now // // Secondes if (!st.hasMoreTokens()) { return calendar; } String tok = st.nextToken(); if (tok.equals(":")) { // secondes if (st.hasMoreTokens()) { int secondes = Integer.parseInt(st.nextToken()); calendar.set(Calendar.SECOND, secondes); if (!st.hasMoreTokens()) { return calendar; } // frac sec tok = st.nextToken(); if (tok.equals(".")) { // bug fixed, thx to Martin Bottcher String nt = st.nextToken(); while (nt.length() < 3) { nt += "0"; } nt = nt.substring(0, 3); // Cut trailing chars.. int millisec = Integer.parseInt(nt); // int millisec = Integer.parseInt(st.nextToken()) * 10; calendar.set(Calendar.MILLISECOND, millisec); if (!st.hasMoreTokens()) { return calendar; } tok = st.nextToken(); } else { calendar.set(Calendar.MILLISECOND, 0); } } else { throw new RuntimeException("No secondes specified"); } } else { calendar.set(Calendar.SECOND, 0); calendar.set(Calendar.MILLISECOND, 0); } // Timezone if (!tok.equals("Z")) { // UTC if (!(tok.equals("+") || tok.equals("-"))) { throw new RuntimeException("only Z, + or - allowed"); } boolean plus = tok.equals("+"); if (!st.hasMoreTokens()) { throw new RuntimeException("Missing hour field"); } int tzhour = Integer.parseInt(st.nextToken()); int tzmin = 0; if (check(st, ":") && (st.hasMoreTokens())) { tzmin = Integer.parseInt(st.nextToken()); } else { throw new RuntimeException("Missing minute field"); } if (plus) { calendar.add(Calendar.HOUR, -tzhour); calendar.add(Calendar.MINUTE, -tzmin); } else { calendar.add(Calendar.HOUR, tzhour); calendar.add(Calendar.MINUTE, tzmin); } } } catch (NumberFormatException ex) { throw new RuntimeException("[" + ex.getMessage() + "] is not an integer"); } return calendar; }
From source file:com.livinglogic.ul4.FunctionAsJSON.java
private static void call(StringBuilder builder, Object obj) { if (obj == null) builder.append("null"); else if (obj instanceof Boolean) builder.append(((Boolean) obj).booleanValue() ? "true" : "false"); else if (obj instanceof Integer || obj instanceof Byte || obj instanceof Short || obj instanceof Long || obj instanceof BigInteger || obj instanceof Double || obj instanceof Float) builder.append(obj.toString());/*from w w w . j a v a2 s . c om*/ else if (obj instanceof BigDecimal) { String result = obj.toString(); builder.append(result); if (result.indexOf('.') < 0 || result.indexOf('E') < 0 || result.indexOf('e') < 0) builder.append(".0"); } else if (obj instanceof String) builder.append("\"") // We're using StringEscapeUtils.escapeJava() here, which is the same as escapeJavaScript, except that it doesn't escape ' (which is illegal in JSON strings according to json.org) .append(StringEscapeUtils.escapeJava(((String) obj))).append("\""); else if (obj instanceof Date) { Calendar calendar = new GregorianCalendar(); calendar.setTime((Date) obj); builder.append("new Date(").append(calendar.get(Calendar.YEAR)).append(", ") .append(calendar.get(Calendar.MONTH)).append(", ").append(calendar.get(Calendar.DAY_OF_MONTH)) .append(", ").append(calendar.get(Calendar.HOUR_OF_DAY)).append(", ") .append(calendar.get(Calendar.MINUTE)).append(", ").append(calendar.get(Calendar.SECOND)); int milliSeconds = calendar.get(Calendar.MILLISECOND); if (milliSeconds != 0) { builder.append(", ").append(milliSeconds); } builder.append(")"); } else if (obj instanceof InterpretedTemplate) { builder.append("ul4.Template.loads(\"") .append(StringEscapeUtils.escapeJavaScript(((InterpretedTemplate) obj).dumps())).append("\")"); } else if (obj instanceof TemplateClosure) { builder.append("ul4.Template.loads(\"") .append(StringEscapeUtils.escapeJavaScript(((TemplateClosure) obj).getTemplate().dumps())) .append("\")"); } else if (obj instanceof UL4Attributes) { builder.append("{"); boolean first = true; Set<String> attributeNames = ((UL4Attributes) obj).getAttributeNamesUL4(); for (String attributeName : attributeNames) { if (first) first = false; else builder.append(", "); call(builder, attributeName); builder.append(": "); Object value = ((UL4Attributes) obj).getItemStringUL4(attributeName); call(builder, value); } builder.append("}"); } else if (obj instanceof Color) { Color c = (Color) obj; builder.append("ul4.Color.create(").append(c.getR()).append(", ").append(c.getG()).append(", ") .append(c.getB()).append(", ").append(c.getA()).append(")"); } else if (obj instanceof Collection) { builder.append("["); boolean first = true; for (Object o : (Collection) obj) { if (first) first = false; else builder.append(", "); call(builder, o); } builder.append("]"); } else if (obj instanceof Object[]) { builder.append("["); boolean first = true; for (Object o : (Object[]) obj) { if (first) first = false; else builder.append(", "); call(builder, o); } builder.append("]"); } else if (obj instanceof Map) { builder.append("{"); boolean first = true; Set<Map.Entry> entrySet = ((Map) obj).entrySet(); for (Map.Entry entry : entrySet) { if (first) first = false; else builder.append(", "); call(builder, entry.getKey()); builder.append(": "); call(builder, entry.getValue()); } builder.append("}"); } }
From source file:net.seratch.taskun.util.CalendarUtil.java
public static Calendar getCalendar(String yyyy, String mm, String dd) { Calendar cal = Calendar.getInstance(); cal.set(Calendar.YEAR, Integer.valueOf(yyyy)); cal.set(Calendar.MONTH, Integer.valueOf(mm) - 1); cal.set(Calendar.DATE, Integer.valueOf(dd)); cal.set(Calendar.HOUR_OF_DAY, 0); cal.set(Calendar.MINUTE, 0);// w w w . ja v a 2 s . c om cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); return cal; }