canonical example by Tabnine
public boolean isDateExpired(String input, Date expiration) throws ParseException { DateFormat dateFormat = new SimpleDateFormat ("dd/MM/yyyy"); Date date = dateFormat.parse(input); return date.after(expiration); }
try { String string1 = "20:11:13"; Date time1 = new SimpleDateFormat("HH:mm:ss").parse(string1); Calendar calendar1 = Calendar.getInstance(); calendar1.setTime(time1); String string2 = "14:49:00"; Date time2 = new SimpleDateFormat("HH:mm:ss").parse(string2); Calendar calendar2 = Calendar.getInstance(); calendar2.setTime(time2); calendar2.add(Calendar.DATE, 1); String someRandomTime = "01:00:00"; Date d = new SimpleDateFormat("HH:mm:ss").parse(someRandomTime); Calendar calendar3 = Calendar.getInstance(); calendar3.setTime(d); calendar3.add(Calendar.DATE, 1); Date x = calendar3.getTime(); if (x.after(calendar1.getTime()) && x.before(calendar2.getTime())) { //checkes whether the current time is between 14:49:00 and 20:11:13. System.out.println(true); } } catch (ParseException e) { e.printStackTrace(); }
afterTime = new Date(System.currentTimeMillis() + 1000L); } else { afterTime = new Date(afterTime.getTime() + 1000L); if(afterTime.before(startTime)) afterTime = startTime; afterTimePastEndTimeOfDay = afterTime.getTime() > endTimeOfDay.getTimeOfDayForDate(afterTime).getTime(); if (fireTime.before(fireTimeStartDate)) { return fireTimeStartDate; if (fireTime.after(fireTimeEndDate)) { fireTime = advanceToNextDayOfWeekIfNecessary(fireTime, isSameDay(fireTime, fireTimeEndDate));
long nowTime = now.getTime(); Date max = allowSkew ? new Date(maxTime) : now; if (max.after(exp)) { String expVal = DateFormats.formatIso8601(exp, false); String nowVal = DateFormats.formatIso8601(now, false); long differenceMillis = maxTime - exp.getTime(); Date min = allowSkew ? new Date(minTime) : now; if (min.before(nbf)) { String nbfVal = DateFormats.formatIso8601(nbf, false); String nowVal = DateFormats.formatIso8601(now, false); long differenceMillis = nbf.getTime() - minTime;
final Calendar scheduleTime = Calendar.getInstance(); scheduleTime.setTimeZone(TimeZone.getTimeZone(timezone)); startDate = new Date(); scheduleTime.setTime(startDate); if (execDate.before(new Date()) || !execDate.after(startDate)) { scheduleTime.add(Calendar.HOUR_OF_DAY, 1); scheduleTime.set(Calendar.MILLISECOND, 0); try { execDate = scheduleTime.getTime(); } catch (IllegalArgumentException ex) { scheduleTime.setLenient(true); if (execDate.before(new Date()) || !execDate.after(startDate)) { scheduleTime.add(Calendar.DAY_OF_YEAR, 1); if (execDate.before(new Date()) || !execDate.after(startDate)) { scheduleTime.add(Calendar.DAY_OF_WEEK, 7); if (execDate.before(new Date()) || !execDate.after(startDate)) { scheduleTime.add(Calendar.MONTH, 1);
public static int getBetweenTodaysStartDateAndEndDate(Date startDate, Date endDate) { byte betweentoday = 0; if(startDate == null) { return betweentoday; } else { if(endDate == null) { Calendar calendar = Calendar.getInstance(); String year = Integer.toString(calendar.get(Calendar.YEAR)); String month = Integer.toString(calendar.get(Calendar.MONTH) + 1); String day = Integer.toString(calendar.get(Calendar.DATE)); String strtodaytime = year + "-" + month + "-" + day; SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); try { endDate = formatter.parse(strtodaytime); } catch (ParseException var10) { var10.printStackTrace(); } } int betweentoday1; if(endDate.after(startDate)) { betweentoday1 = (int)((endDate.getTime() - startDate.getTime()) / 86400000L); } else { betweentoday1 = (int)((startDate.getTime() - endDate.getTime()) / 86400000L); } return betweentoday1; } }
public static int getDaysBetween( Date date1, Date date2, TimeZone timeZone) { if (date1.after(date2)) { Date tempDate = date1; endCal = new GregorianCalendar(timeZone); offsetDate1 = timeZone.getOffset(date1.getTime()); offsetDate2 = timeZone.getOffset(date2.getTime()); startCal.setTime(date1); startCal.add(Calendar.MILLISECOND, offsetDate1); endCal.setTime(date2); endCal.add(Calendar.MILLISECOND, offsetDate2); while (CalendarUtil.beforeByDay(startCal.getTime(), endCal.getTime())) { startCal.add(Calendar.DAY_OF_MONTH, 1);
public static Object DateWorkingDiff( ValueMetaInterface metaA, Object dataA, ValueMetaInterface metaB, Object dataB ) throws KettleValueException { if ( dataA != null && dataB != null ) { Date fromDate = metaB.getDate( dataB ); Date toDate = metaA.getDate( dataA ); boolean singminus = false; if ( fromDate.after( toDate ) ) { singminus = true; Date temp = fromDate; fromDate = toDate; toDate = temp; } Calendar calFrom = Calendar.getInstance(); calFrom.setTime( fromDate ); Calendar calTo = Calendar.getInstance(); calTo.setTime( toDate ); int iNoOfWorkingDays = 0; do { if ( calFrom.get( Calendar.DAY_OF_WEEK ) != Calendar.SATURDAY && calFrom.get( Calendar.DAY_OF_WEEK ) != Calendar.SUNDAY ) { iNoOfWorkingDays += 1; } calFrom.add( Calendar.DATE, 1 ); } while ( calFrom.getTimeInMillis() <= calTo.getTimeInMillis() ); return new Long( singminus ? -iNoOfWorkingDays : iNoOfWorkingDays ); } else { return null; } }
protected void handleHoliday(Calendar c, boolean resetTime) { if (!holidays.isEmpty()) { Date current = c.getTime(); for (TimePeriod holiday : holidays) { // check each holiday if it overlaps current date and break after first match if (current.after(holiday.getFrom()) && current.before(holiday.getTo())) { Calendar tmp = new GregorianCalendar(); tmp.setTime(holiday.getTo()); Calendar tmp2 = new GregorianCalendar(); tmp2.setTime(current); tmp2.set(Calendar.HOUR_OF_DAY, 0); tmp2.set(Calendar.MINUTE, 0); tmp2.set(Calendar.SECOND, 0); tmp2.set(Calendar.MILLISECOND, 0); long difference = tmp.getTimeInMillis() - tmp2.getTimeInMillis(); c.add(Calendar.HOUR_OF_DAY, (int) (difference/HOUR_IN_MILLIS)); handleWeekend(c, resetTime); break; } } } }
protected boolean evaluateUntil(String timestamp) { try { return DATE_FORMAT.parse(timestamp).after(Calendar.getInstance().getTime()); } catch (ParseException e) { return false; } }
public static String getTimePrefix(Date date, boolean quarterScope) { String time_prefix; Calendar calendar = Calendar.getInstance(); calendar.setTime(date); int year = calendar.get(Calendar.YEAR); int diff = 1 - Calendar.JANUARY; int month = calendar.get(Calendar.MONTH) + diff; int day = calendar.get(Calendar.DATE); if(quarterScope) { year = calendar.get(Calendar.YEAR); if (date.after(quarter3)) calendar.setTime(quarter3); else if(date.after(quarter2)) calendar.setTime(quarter2); else if(date.after(quarter1)) calendar.setTime(quarter1); else { year--; calendar.setTime(quarter4); } month = calendar.get(Calendar.MONTH) + diff; day = calendar.get(Calendar.DATE); } time_prefix = String.valueOf(year) + String.format("%02d", month) + String.format("%02d", day); return time_prefix; }
if (minDate != null && !date.equals(minDate) && date.before(minDate)) { setValid(false); if (maxDate != null && !date.equals(maxDate) && date.after(maxDate)) { setValid(false); List<Object> disabledDates = getDisabledDates(); if (disabledDates != null) { Calendar c = Calendar.getInstance(CalendarUtils.calculateTimeZone(getTimeZone()), calculateLocale(context)); c.setTime(date); int sYear = c.get(Calendar.YEAR); int sMonth = c.get(Calendar.MONTH); if (disabledDate instanceof Date) { c.clear(); c.setTime((Date) disabledDate); List<Object> disabledDays = getDisabledDays(); if (disabledDays != null) { Calendar c = Calendar.getInstance(CalendarUtils.calculateTimeZone(getTimeZone()), calculateLocale(context)); c.setTime(date); int dayOfWeek = c.get(Calendar.DAY_OF_WEEK) - 1;
Calendar cal = Calendar.getInstance(); cal.set( Calendar.MILLISECOND, 0 ); if ( cal.getTime().after( lastModified ) ) Calendar cal = Calendar.getInstance(); cal.add( Calendar.MINUTE, -minutes ); if ( cal.getTime().after( lastModified ) )