List of usage examples for java.util Calendar clear
public final void clear()
Calendar
undefined. From source file:org.kuali.rice.core.framework.persistence.jdbc.sql.SQLUtils.java
public static Timestamp convertStringDateToTimestamp(String dateWithoutTime) { Pattern p = Pattern.compile(TIME_REGEX); Matcher util = p.matcher(dateWithoutTime); if (util.find()) { dateWithoutTime = StringUtils.substringBeforeLast(dateWithoutTime, " "); }//from www. j a va2s.co m DateComponent formattedDate = formatDateToDateComponent(dateWithoutTime, REGEX_EXPRESSION_MAP_TO_REGEX_SPLIT_EXPRESSION.keySet()); if (formattedDate == null) { return null; } Calendar c = Calendar.getInstance(); c.clear(); c.set(Calendar.MONTH, Integer.valueOf(formattedDate.getMonth()).intValue() - 1); c.set(Calendar.DATE, Integer.valueOf(formattedDate.getDate()).intValue()); c.set(Calendar.YEAR, Integer.valueOf(formattedDate.getYear()).intValue()); return convertCalendar(c); }
From source file:org.appcelerator.util.DateUtil.java
/** * gets tomorrow as a date//from w ww .j av a 2s.c om * * @return tomorrow */ public static Date tommorow() { Calendar calendar = new GregorianCalendar(GMT_TZ); calendar.setTime(new Date()); Calendar tommorow = new GregorianCalendar(GMT_TZ); tommorow.clear(); tommorow.set(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DATE)); tommorow.add(Calendar.DATE, 1); return tommorow.getTime(); }
From source file:com.tesora.dve.db.mysql.common.MysqlAPIUtils.java
/** * Methods to read and write length coded dates in the Binary Protocol * // w ww . j a v a2s .c om * if year, month, day, hour, minutes, seconds and micro_seconds are all 0, * length is 0 and no other field is sent if hour, minutes, seconds and * micro_seconds are all 0, length is 4 and no other field is sent if * micro_seconds is 0, length is 7 and micro_seconds is not sent otherwise * length is 11 * * Fields * length (1) -- number of bytes following (valid values: 0, 4, 7, 11) * year (2) -- year * month (1) -- month * day (1) -- day * hour (1) -- hour * minute (1) -- minutes * second (1) -- seconds * micro_second (4) -- micro-seconds * */ public static Date getLengthCodedDate(ByteBuf cb) throws PEException { final Calendar cal = Calendar.getInstance(); cal.clear(); short length = cb.readUnsignedByte(); if (length >= 4) { cal.set(Calendar.YEAR, cb.readUnsignedShort()); cal.set(Calendar.MONTH, cb.readByte() - 1); // MONTH is zero based cal.set(Calendar.DAY_OF_MONTH, cb.readByte()); if (length >= 7) { cal.set(Calendar.HOUR_OF_DAY, cb.readByte()); cal.set(Calendar.MINUTE, cb.readByte()); cal.set(Calendar.SECOND, cb.readByte()); } if (length == 11) { long microSeconds = cb.readUnsignedInt(); cal.set(Calendar.MILLISECOND, (int) (microSeconds / 1000)); } if (length > 11) { throw new PEException("Invalid length specified to date type (" + length + ")"); } return cal.getTime(); } return null; }
From source file:org.openvpms.web.resource.i18n.format.DateFormatter.java
/** * Parse a time from a string, expected to be of the form [H]HMM. * * @param value the string to parse// w w w . j a v a2s . c om * @param allow24 if {@code true}, allow hours in the range 0..24, else 0..23 * @return the parsed time * @throws NumberFormatException if the hours or minutes can't be parsed * @throws IllegalArgumentException if the hours or minutes exceed the range */ private static Date parseHoursMins(String value, boolean allow24) { String hourPart; if (value.length() == 3) { hourPart = value.substring(0, 1); } else { hourPart = value.substring(0, 2); } int hours = getHours(hourPart, allow24); String minPart = value.substring(hourPart.length()); int mins = Integer.parseInt(minPart); if (mins < 0 || mins > 59) { throw new IllegalArgumentException("Minutes exceed range 0..59: " + minPart); } if (hours == 24 && mins > 0) { throw new IllegalArgumentException("Maximum time (24:00) exceeded"); } Calendar calendar = new GregorianCalendar(); calendar.clear(); // get rid of date, timezone info calendar.set(Calendar.HOUR_OF_DAY, hours); calendar.set(Calendar.MINUTE, mins); return calendar.getTime(); }
From source file:org.finra.dm.core.DmDateUtils.java
/** * Returns a calendar for the current day that does not have the time set. * * @return the current date.//from w w w . j a v a 2 s .c o m */ public static Calendar getCurrentCalendarNoTime() { // Get the current year, month, and day before we clear out the fields. Calendar calendar = Calendar.getInstance(); int year = calendar.get(Calendar.YEAR); int month = calendar.get(Calendar.MONTH); int day = calendar.get(Calendar.DATE); // Clear out ALL the fields of the calendar. If any are not cleared, we run the risk of something being set that we don't want. calendar.clear(); // Update the calendar with just the year, month, and day. calendar.set(year, month, day); // Return the updated calendar. return calendar; }
From source file:org.medici.bia.common.util.DateUtils.java
/** * /* www. jav a 2 s .c o m*/ * @return */ public static Date getFirstDayOfCurrentMonth() { Calendar nowCal = Calendar.getInstance(); int month = nowCal.get(Calendar.MONTH); int year = nowCal.get(Calendar.YEAR); Calendar calendar = Calendar.getInstance(); calendar.clear(); calendar.set(Calendar.YEAR, year); calendar.set(Calendar.MONTH, month); calendar.set(Calendar.DAY_OF_MONTH, 1); return new Date(calendar.getTimeInMillis()); }
From source file:cn.ipanel.apps.portalBackOffice.util.CommonsFiend.java
/** * // ww w . j av a 2s . c o m * * @param date * yyyy-MM * @return * @author lixiang * @throws ParseException * @create 2008-9-22 01:59:33 * @since */ public static List getDatesList(String date) throws ParseException { DateFormat format = new SimpleDateFormat("yyyy-MM"); Calendar time = Calendar.getInstance(); time.clear(); Date d1 = format.parse(date); time.setTime(d1); int day = time.getActualMaximum(Calendar.DAY_OF_MONTH); DateFormat formats = new SimpleDateFormat(Defines.FORMAT_DATE_STRING); List list = new ArrayList(); for (int i = 1; i <= day; i++) { String s = format.format(d1) + "-" + i; Date sss = formats.parse(s); String dd = formats.format(sss); list.add(dd); } return list; }
From source file:com.clustercontrol.collect.util.CollectDataUtil.java
/** * ???? Queue ? put ?//from www. j a v a 2 s .c o m * * @param sample * * @throws HinemosUnknown * @throws Exception */ public static void put(List<Sample> sampleList) { m_log.debug("put() start"); List<CollectData> collectdata_entities = new ArrayList<CollectData>(); List<SummaryHour> summaryhour_entities = new ArrayList<SummaryHour>(); List<SummaryDay> summaryday_entities = new ArrayList<SummaryDay>(); List<SummaryMonth> summarymonth_entities = new ArrayList<SummaryMonth>(); JpaTransactionManager jtm = new JpaTransactionManager(); jtm.begin(); for (Sample sample : sampleList) { // for debug if (m_log.isDebugEnabled()) { m_log.debug("put() dateTime = " + sample.getDateTime()); ArrayList<PerfData> list = sample.getPerfDataList(); for (PerfData data : list) { m_log.info("put() list facilityId = " + data.getFacilityId() + ", value = " + data.getValue()); } } ArrayList<PerfData> list = sample.getPerfDataList(); String monitorId = sample.getMonitorId(); Long time = HinemosTime.currentTimeMillis(); for (PerfData data : list) { m_log.debug("persist itemCode = " + data.getItemName()); String itemName = data.getItemName(); String facilityId = data.getFacilityId(); String displayName = data.getDisplayName(); CollectData collectData = null; SummaryHour summaryHour_c = null; SummaryDay summaryDay_c = null; SummaryMonth summaryMonth_c = null; Integer collectorid = getId(itemName, displayName, monitorId, facilityId, jtm); CollectDataPK pk = new CollectDataPK(collectorid, time); Float value = null; if (data.getValue() != null) { value = Float.parseFloat(data.getValue().toString()); } collectData = new CollectData(pk, value); collectdata_entities.add(collectData); // Summary?? // ?????? Long hour = (time + TIMEZONE) / 1000 / 3600 * 3600 * 1000 - TIMEZONE; // ??????? Long day = (time + TIMEZONE) / 1000 / 3600 / 24 * 24 * 3600 * 1000 - TIMEZONE; // ??? Calendar calendar = HinemosTime.getCalendarInstance(); calendar.setTimeInMillis(time); int y = calendar.get(Calendar.YEAR); int m = calendar.get(Calendar.MONTH); calendar.clear(); calendar.set(y, m, 1); Long month = calendar.getTimeInMillis(); // SummaryHour CollectDataPK pk_h = new CollectDataPK(collectorid, hour); try { SummaryHour summaryHour = QueryUtil.getSummaryHour(pk_h); summaryHour_c = summaryHour.clone(); Integer h_count = summaryHour_c.getCount(); if (value != null) { summaryHour_c.setAvg((value + summaryHour_c.getAvg() * h_count) / (h_count + 1)); summaryHour_c.setMin(summaryHour_c.getMin() < value ? summaryHour_c.getMin() : value); summaryHour_c.setMax(summaryHour_c.getMax() > value ? summaryHour_c.getMax() : value); } else { summaryHour_c.setAvg(summaryHour_c.getAvg() * h_count / (h_count + 1)); summaryHour_c.setMin(summaryHour_c.getMin()); summaryHour_c.setMax(summaryHour_c.getMax()); } summaryHour_c.setCount(h_count + 1); } catch (CollectKeyNotFound e) { summaryHour_c = new SummaryHour(pk_h, value, value, value, 1); } // SummaryDay CollectDataPK pk_d = new CollectDataPK(collectorid, day); try { SummaryDay summaryDay = QueryUtil.getSummaryDay(pk_d); summaryDay_c = summaryDay.clone(); Integer d_count = summaryDay_c.getCount(); if (value != null) { summaryDay_c.setAvg((value + summaryDay_c.getAvg() * d_count) / (d_count + 1)); summaryDay_c.setMin(summaryDay_c.getMin() < value ? summaryDay_c.getMin() : value); summaryDay_c.setMax(summaryDay_c.getMax() > value ? summaryDay_c.getMax() : value); } else { summaryDay_c.setAvg(summaryDay_c.getAvg() * d_count / (d_count + 1)); summaryDay_c.setMin(summaryDay_c.getMin()); summaryDay_c.setMax(summaryDay_c.getMax()); } summaryDay_c.setCount(d_count + 1); } catch (CollectKeyNotFound e) { summaryDay_c = new SummaryDay(pk_d, value, value, value, 1); } // SummaryMonth CollectDataPK pk_m = new CollectDataPK(collectorid, month); try { SummaryMonth summaryMonth = QueryUtil.getSummaryMonth(pk_m); summaryMonth_c = summaryMonth.clone(); Integer m_count = summaryMonth_c.getCount(); if (value != null) { summaryMonth_c.setAvg((value + summaryMonth_c.getAvg() * m_count) / (m_count + 1)); summaryMonth_c.setMin(summaryMonth_c.getMin() < value ? summaryMonth_c.getMin() : value); summaryMonth_c.setMax(summaryMonth_c.getMax() > value ? summaryMonth_c.getMax() : value); } else { summaryMonth_c.setAvg(summaryMonth_c.getAvg() * m_count / (m_count + 1)); summaryMonth_c.setMin(summaryMonth_c.getMin()); summaryMonth_c.setMax(summaryMonth_c.getMax()); } summaryMonth_c.setCount(m_count + 1); } catch (CollectKeyNotFound e) { summaryMonth_c = new SummaryMonth(pk_m, value, value, value, 1); } summaryhour_entities.add(summaryHour_c); summaryday_entities.add(summaryDay_c); summarymonth_entities.add(summaryMonth_c); } m_log.debug("insert() end : dateTime = " + sample.getDateTime()); } jtm.commit(); List<JdbcBatchQuery> query = new ArrayList<JdbcBatchQuery>(); // ()? if (!collectdata_entities.isEmpty()) { query.add(new CollectDataJdbcBatchInsert(collectdata_entities)); } if (!summaryhour_entities.isEmpty()) { query.add(new SummaryHourJdbcBatchUpsert(summaryhour_entities)); } if (!summaryday_entities.isEmpty()) { query.add(new SummaryDayJdbcBatchUpsert(summaryday_entities)); } if (!summarymonth_entities.isEmpty()) { query.add(new SummaryMonthJdbcBatchUpsert(summarymonth_entities)); } JdbcBatchExecutor.execute(query); jtm.close(); m_log.debug("put() end"); }
From source file:com.greenline.guahao.biz.util.DateUtils.java
public static String getToSearchShiftCaseDate(String toSearchShiftCaseDate) { if (StringUtils.isBlank(toSearchShiftCaseDate) || SearchExpertsDO.NOT_LIMIT.equals(toSearchShiftCaseDate) || "??".equals(toSearchShiftCaseDate)) { return null; }//w ww.j ava2 s .c o m toSearchShiftCaseDate = toSearchShiftCaseDate.replaceAll("-", "");// ?yyyy-MM-dd? if (!isNumeric(toSearchShiftCaseDate) || toSearchShiftCaseDate.length() != 8) { logger.error("?" + toSearchShiftCaseDate); return null; } SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd"); Calendar c = Calendar.getInstance(); try { Date date = sdf.parse(toSearchShiftCaseDate); c.clear(); c.setTime(date); // 235959 c.set(Calendar.HOUR_OF_DAY, 23); c.set(Calendar.MINUTE, 59); c.set(Calendar.SECOND, 59); SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); return simpleDateFormat.format(c.getTime()); } catch (Exception e) { logger.error("???" + toSearchShiftCaseDate, e); } return null; }
From source file:com.bjorsond.android.timeline.utilities.Utilities.java
public static Date getLastDayOfMonth(Date dateInMonth) { Calendar calendar = Calendar.getInstance(); calendar.setTime(dateInMonth);/* www . jav a 2s . c om*/ int lastDate = calendar.getActualMaximum(Calendar.DATE); calendar.clear(); calendar.set(Calendar.DATE, lastDate); return calendar.getTime(); }