List of usage examples for java.util Calendar MONTH
int MONTH
To view the source code for java.util Calendar MONTH.
Click Source Link
get
and set
indicating the month. From source file:Gestores.GestorUsuarios.java
public void registraUsuario(Restaurante restaurante) { Calendar cal = new GregorianCalendar(); String fecha = cal.get(Calendar.YEAR) + "-" + (cal.get(Calendar.MONTH) + 1) + "-" + cal.get(Calendar.DAY_OF_MONTH); try {//from w w w.j ava 2 s .co m String query = "INSERT INTO restaurante (nombre, direccion, telefono, username, passwd, web, email, fecha) " + "VALUES (?,?,?,?,?,?,?,?)"; jdbcTemplate.update(query, new Object[] { restaurante.getNombre(), restaurante.getDireccion(), restaurante.getTelefono(), restaurante.getUsername(), gHash.md5(restaurante.getPassword()), restaurante.getWeb(), restaurante.getEmail(), fecha }); } catch (Exception e) { General.log("GestorUsuarios", "ERROR en registraUsuario: " + e.getMessage()); } }
From source file:com.hybris.datahub.outbound.utils.CommonUtils.java
/** * Get all dates within three months/*from w ww . j a va2 s .c om*/ * * @param startDate * @param nowDate * * @return Sample Data: * <p> * key:value-->start:2001-01-01 00:00:00 <br> * or <br> * end:2001-01-01 23:59:59 <br> */ public static List<Map<String, Date>> findDates(Date startDate, Date nowDate) { final List<Map<String, Date>> lDate = new ArrayList<Map<String, Date>>(); final SimpleDateFormat ymd = new SimpleDateFormat("yyyy-MM-dd"); final SimpleDateFormat ymdmhs = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); final Calendar calendar = Calendar.getInstance(); if (nowDate == null && startDate == null) { nowDate = calendar.getTime(); calendar.add(Calendar.MONTH, -3); startDate = calendar.getTime(); } else if (nowDate != null && startDate == null) { calendar.add(Calendar.MONTH, -3); startDate = calendar.getTime(); } else if (nowDate == null && startDate != null) { nowDate = calendar.getTime(); } try { final Map<String, Date> beginItem = new HashMap<String, Date>(); beginItem.put("start", ymdmhs.parse(ymd.format(startDate) + " 00:00:00")); beginItem.put("end", ymdmhs.parse(ymd.format(startDate) + " 23:59:59")); lDate.add(beginItem); final Calendar calBegin = Calendar.getInstance(); calBegin.setTime(startDate); final Calendar calEnd = Calendar.getInstance(); calEnd.setTime(startDate); while (ymd.parse(ymd.format(nowDate)).after(calBegin.getTime())) { calBegin.add(Calendar.DAY_OF_MONTH, 1); final Map<String, Date> dateItem = new HashMap<String, Date>(); dateItem.put("start", ymdmhs.parse(ymd.format(calBegin.getTime()) + " 00:00:00")); dateItem.put("end", ymdmhs.parse(ymd.format(calBegin.getTime()) + " 23:59:59")); lDate.add(dateItem); } } catch (final ParseException e) { LOGGER.error(e.getMessage()); } return lDate; }
From source file:com.qpark.eip.core.spring.auth.LimitedAccessDataProvider.java
/** * Get a {@link Date}, where hours, minutes, seconds and milliseconds are * set to 0./* w w w.j a v a2 s. co m*/ * * @return the {@link Date} and the corresponding log string. */ private static SimpleEntry<Date, String> getRequestDate() { Calendar gc = new GregorianCalendar(); gc.set(Calendar.HOUR_OF_DAY, 0); gc.set(Calendar.MINUTE, 0); gc.set(Calendar.SECOND, 0); gc.set(Calendar.MILLISECOND, 0); String hmss = String.format("%04d%02d%02d", gc.get(Calendar.YEAR), gc.get(Calendar.MONTH) + 1, gc.get(Calendar.DAY_OF_MONTH)); SimpleEntry<Date, String> entry = new SimpleEntry<Date, String>(gc.getTime(), hmss); return entry; }
From source file:com.arvato.thoroughly.util.CommonUtils.java
/** * Get all dates within three months// ww w.j a v a 2s . c o m * * @param startDate * @param nowDate * * @return Sample Data: * <p> * key:value-->start:2001-01-01 00:00:00 <br> * or <br> * end:2001-01-01 23:59:59 <br> */ public static List<Map<String, Date>> findDates(Date startDate, Date nowDate) { List<Map<String, Date>> lDate = new ArrayList<Map<String, Date>>(); SimpleDateFormat ymd = new SimpleDateFormat("yyyy-MM-dd", Locale.CHINA); SimpleDateFormat ymdmhs = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.CHINA); Calendar calendar = Calendar.getInstance(); if (nowDate == null && startDate == null) { nowDate = calendar.getTime(); calendar.add(Calendar.MONTH, -3); startDate = calendar.getTime(); } else if (nowDate != null && startDate == null) { calendar.add(Calendar.MONTH, -3); startDate = calendar.getTime(); } else if (nowDate == null && startDate != null) { nowDate = calendar.getTime(); } try { Map<String, Date> beginItem = new HashMap<String, Date>(); beginItem.put("start", ymdmhs.parse(ymd.format(startDate) + " 00:00:00")); beginItem.put("end", ymdmhs.parse(ymd.format(startDate) + " 23:59:59")); lDate.add(beginItem); Calendar calBegin = Calendar.getInstance(); calBegin.setTime(startDate); Calendar calEnd = Calendar.getInstance(); calEnd.setTime(startDate); while (ymd.parse(ymd.format(nowDate)).after(calBegin.getTime())) { calBegin.add(Calendar.DAY_OF_MONTH, 1); Map<String, Date> dateItem = new HashMap<String, Date>(); dateItem.put("start", ymdmhs.parse(ymd.format(calBegin.getTime()) + " 00:00:00")); dateItem.put("end", ymdmhs.parse(ymd.format(calBegin.getTime()) + " 23:59:59")); lDate.add(dateItem); } } catch (ParseException e) { LOGGER.error(e.getMessage()); } return lDate; }
From source file:com.clican.pluto.dataprocess.dpl.function.impl.Duration.java
public static double duration(Date d1, Date d2, String step) throws PrefixAndSuffixException { if (StringUtils.isEmpty(step) || step.equals("day")) { return (d1.getTime() - d2.getTime()) / (1000L * 3600 * 24); } else if (step.equals("month")) { Calendar c1 = Calendar.getInstance(); c1.setTime(d1);/* w w w. j a va2 s. c om*/ Calendar c2 = Calendar.getInstance(); c2.setTime(d2); int month = (c1.get(Calendar.YEAR) - c2.get(Calendar.YEAR)) * 12 + (c1.get(Calendar.MONTH) - c2.get(Calendar.MONTH)); return month; } else { throw new PrefixAndSuffixException("??"); } }
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); 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 ww w. j av a 2 s . c o m }
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.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());/*ww w . j a v a2s . c o m*/ 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:com.eryansky.common.utils.DateUtil.java
/** * ? ?2009-08-01/*from ww w.j a v a 2 s.c o m*/ */ public static String monthFist() { Calendar localTime = Calendar.getInstance(); String strY = null;// int x = localTime.get(Calendar.YEAR); // int y = localTime.get(Calendar.MONTH) + 1; // strY = y >= 10 ? String.valueOf(y) : ("0" + y); // ? return x + "-" + strY + "-01"; // ???yyyy-mm-dd? }
From source file:Dates.java
/** * Returns the month (1 to 12) of date. <p> * /*from w ww. j a v a2s . c o m*/ * If date is null returns 0. */ public static int getMonth(Date date) { if (date == null) return 0; Calendar cal = Calendar.getInstance(); cal.setTime(date); return cal.get(Calendar.MONTH) + 1; }