List of usage examples for org.apache.commons.lang3.time DateUtils truncate
public static Date truncate(final Object date, final int field)
Truncates a date, leaving the field specified as the most significant field.
For example, if you had the date-time of 28 Mar 2002 13:45:01.231, if you passed with HOUR, it would return 28 Mar 2002 13:00:00.000.
From source file:com.thinkbiganalytics.jobrepo.query.model.transform.JobStatusTransform.java
/** * Enusre that the list contains a date matching Now - the Period. if not add it to the collection */// w w w. j ava 2 s . c om public static void ensureDateFromPeriodExists(List<JobStatusCount> jobStatusCounts, Period period) { //add in the very first date relative to the period if it doesnt exist with a count of 0 if (jobStatusCounts != null && !jobStatusCounts.isEmpty()) { //get the first min date in the result set Date firstDateInResultSet = jobStatusCounts.stream().map(jobStatusCount -> jobStatusCount.getDate()) .min(Date::compareTo).get(); Date firstDate = DateUtils.truncate(DateTimeUtil.getNowUTCTime().minus(period).toDate(), Calendar.DATE); boolean containsFirstDate = jobStatusCounts.stream() .anyMatch(jobStatusCount -> jobStatusCount.getDate().equals(firstDate)); if (!containsFirstDate) { JobStatusCount first = jobStatusCounts.get(0); JobStatusCount min = new JobStatusCountResult(first); min.setDate(firstDate); min.setCount(new Long(0)); jobStatusCounts.add(min); } } }
From source file:com.webbfontaine.valuewebb.model.validators.MpPriceDateValidator.java
public static boolean validate(Date date) { Date todayDate = DateUtils.truncate(new Date(), Calendar.DAY_OF_MONTH); Date dateWithoutTime = DateUtils.truncate(date, Calendar.DAY_OF_MONTH); return date == null || Integer.parseInt(new SimpleDateFormat("yyyy").format(date)) >= 2010 && !todayDate.before(dateWithoutTime); }
From source file:SampleLang.java
public static void checkDate() throws InterruptedException, ParseException { //date1 created Date date1 = new Date(); //Print the date and time at this instant System.out.println("The time right now is >>" + date1); //Thread sleep for 1000 ms Thread.currentThread().sleep(DateUtils.MILLIS_PER_MINUTE); //date2 created. Date date2 = new Date(); //Check if date1 and date2 have the same day System.out.println("Is Same Day >> " + DateUtils.isSameDay(date1, date2)); //Check if date1 and date2 have the same instance System.out.println("Is Same Instant >> " + DateUtils.isSameInstant(date1, date2)); //Round the hour System.out.println("Date after rounding >>" + DateUtils.round(date1, Calendar.HOUR)); //Truncate the hour System.out.println("Date after truncation >>" + DateUtils.truncate(date1, Calendar.HOUR)); //Three dates in three different formats String[] dates = { "2005.03.24 11:03:26", "2005-03-24 11:03", "2005/03/24" }; //Iterate over dates and parse strings to java.util.Date objects for (int i = 0; i < dates.length; i++) { Date parsedDate = DateUtils.parseDate(dates[i], new String[] { "yyyy/MM/dd", "yyyy.MM.dd HH:mm:ss", "yyyy-MM-dd HH:mm" }); System.out.println("Parsed Date is >>" + parsedDate); }//from w w w . j a v a 2 s . c o m //Display date in HH:mm:ss format System.out.println("Now >>" + DateFormatUtils.ISO_TIME_NO_T_FORMAT.format(System.currentTimeMillis())); }
From source file:com.alibaba.utils.date.CommonDateUtils.java
/** * <pre>//from w w w. j a v a 2 s . c o m * * * 2013.09.20,2 * 2013.09.20 2013.09.21 2013.09.22 * </pre> * @param currentDate * @param days * @return */ public static List<Date> afterCurrentDate(Date currentDate, int days) { List<Date> dateList = new ArrayList<Date>(); // 0. if (currentDate == null) { return null; } if (days <= 0) { dateList.add(DateUtils.truncate(currentDate, Calendar.DAY_OF_MONTH)); return dateList; } // 1. Date startDate = new Date(currentDate.getTime()); for (int i = 0; i <= days; ++i) { Date date = DateUtils.addDays(startDate, i); dateList.add(DateUtils.truncate(date, Calendar.DAY_OF_MONTH)); } return dateList; }
From source file:com.thruzero.common.core.utils.DateTimeFormatUtilsExt.java
/** Return the {@code Calendar.DATE} portion of the given {@code dateTime}. */ public static Date truncateTime(final Date dateTime) { return DateUtils.truncate(dateTime, Calendar.DATE); }
From source file:gaffer.example.gettingstarted.generator.DataGenerator8.java
@Override public Element getElement(final String line) { final String[] t = line.split(","); final Edge.Builder edgeBuilder = new Edge.Builder().group("data").source(t[0]).dest(t[1]).directed(true) .property("visibility", t[3]).property("count", 1L); final Date startDate; try {/*w ww.j a v a 2 s .c om*/ startDate = DateUtils.truncate(new SimpleDateFormat("dd/MM/yyyy HH:mm").parse(t[2]), Calendar.DAY_OF_MONTH); edgeBuilder.property("startDate", startDate).property("endDate", DateUtils.addDays(startDate, 1)); } catch (ParseException e) { throw new IllegalArgumentException("Unable to parse date", e); } return edgeBuilder.build(); }
From source file:com.github.devnied.emvnfccard.utils.TrackUtils.java
/** * Extract track 2 data/*from w w w. ja va 2s . co m*/ * * @param pEmvCard * Object card representation * @param pData * data to parse * @return true if the extraction succeed false otherwise */ public static boolean extractTrack2Data(final EmvCard pEmvCard, final byte[] pData) { boolean ret = false; byte[] track2 = TlvUtil.getValue(pData, EmvTags.TRACK_2_EQV_DATA, EmvTags.TRACK2_DATA); if (track2 != null) { String data = BytesUtils.bytesToStringNoSpace(track2); Matcher m = TRACK2_PATTERN.matcher(data); // Check pattern if (m.find()) { // read card number pEmvCard.setCardNumber(m.group(1)); // Read expire date SimpleDateFormat sdf = new SimpleDateFormat("yyMM", Locale.getDefault()); try { pEmvCard.setExpireDate(DateUtils.truncate(sdf.parse(m.group(2)), Calendar.MONTH)); } catch (ParseException e) { LOGGER.error("Unparsable expire card date : {}", e.getMessage()); return ret; } // Read service pEmvCard.setService(new Service(m.group(3))); ret = true; } } return ret; }
From source file:com.webbfontaine.valuewebb.model.validators.tt.TTDateValidator.java
@Override public boolean isValid(Object value) { int range = Utils.getAppCountry().equals(Constants.GH) ? -3 : -2; if (Utils.currentPage().contains("TtGenList")) { return true; }// w w w . j av a 2 s . c om boolean notFuture; if (value != null && value instanceof Date) { Date dateValue = (Date) value; Calendar cal = Calendar.getInstance(); cal.add(Calendar.YEAR, range); notFuture = !DateUtils.truncate(dateValue, Calendar.DAY_OF_MONTH) .after(DateUtils.truncate(new Date(), Calendar.DAY_OF_MONTH)); // value must not be in future return notFuture && dateValue.after(cal.getTime()); } return true; }
From source file:de.fischer.thotti.reportgen.combiner.AverageDayCombinerIterator.java
@Override Measurement getNextElementComputed() {/*from w ww. j a v a2 s .c om*/ Measurement result = new Measurement(); Date date = DateUtils.truncate(dayOfNextElement, Calendar.DAY_OF_MONTH); result.setPointInTime(date); result.setDuration(durationAggregatedDay / elementsDay); return result; }
From source file:br.com.itfox.utils.Utils.java
public static Timestamp dateToTimestamp(Date utilDate) { long millis = DateUtils.truncate(utilDate, Calendar.MILLISECOND).getTime(); java.sql.Timestamp sq = new java.sql.Timestamp(millis); return sq;//from w ww. ja v a 2 s.c o m }