java.util.Date.after()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(9.4k)|赞(0)|评价(0)|浏览(352)

本文整理了Java中java.util.Date.after()方法的一些代码示例,展示了Date.after()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Date.after()方法的具体详情如下:
包路径:java.util.Date
类名称:Date
方法名:after

Date.after介绍

[英]Returns if this Date is after the specified Date.
[中]如果此日期在指定日期之后,则返回。

代码示例

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);
}

代码示例来源:origin: stackoverflow.com

Date min, max;   // assume these are set to something
Date d;          // the date in question

return d.after(min) && d.before(max);

代码示例来源:origin: facebook/facebook-android-sdk

/**
 * Shows if the user data access is expired.
 *
 * @return true if the data access is expired.
 */
public boolean isDataAccessExpired() {
  return new Date().after(this.dataAccessExpirationTime);
}

代码示例来源:origin: ZHENFENG13/My-Blog

public static boolean nowDateBetweenStartDateAndEndDate(Date startDate, Date endDate) {
  boolean bool = false;
  Date curDate = new Date();
  if(curDate.after(startDate) && curDate.before(endDate)) {
    bool = true;
  }
  return bool;
}

代码示例来源:origin: stackoverflow.com

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();
}

代码示例来源:origin: ctripcorp/apollo

public static String format(Date date) {
 if (date.after(new Date())) {
  return "now";
 long delta = new Date().getTime() - date.getTime();
 if (delta < ONE_MINUTE) {
  long seconds = toSeconds(delta);
 if (date.after(lastDayBeginTime)) {
  return "昨天";
 if (date.after(lastTwoDaysBeginTime)) {
  return "前天";

代码示例来源:origin: quartz-scheduler/quartz

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));

代码示例来源:origin: jwtk/jjwt

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;

代码示例来源:origin: apache/cloudstack

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);

代码示例来源:origin: org.apache.hadoop/hadoop-common

Date now = new Date();
if ((currentOutStream == null) || now.after(nextFlush.getTime())) {
  scheduleFlush(nextFlush.getTime());
 scheduleFlush(new Date());

代码示例来源:origin: ZHENFENG13/My-Blog

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;
  }
}

代码示例来源:origin: com.liferay.portal/com.liferay.portal.kernel

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);

代码示例来源:origin: pentaho/pentaho-kettle

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;
 }
}

代码示例来源:origin: kiegroup/jbpm

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;
      }
    }
  }
  
}

代码示例来源:origin: auth0/java-jwt

private void assertDateIsFuture(Date date, long leeway, Date today) {
  today.setTime(today.getTime() - leeway * 1000);
  if (date != null && today.after(date)) {
    throw new TokenExpiredException(String.format("The Token has expired on %s.", date));
  }
}

代码示例来源:origin: apache/geode

protected boolean evaluateUntil(String timestamp) {
 try {
  return DATE_FORMAT.parse(timestamp).after(Calendar.getInstance().getTime());
 } catch (ParseException e) {
  return false;
 }
}

代码示例来源:origin: decaywood/XueQiuSuperSpider

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;
}

代码示例来源:origin: primefaces/primefaces

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;

代码示例来源:origin: Activiti/Activiti

public Boolean isValidDate(Date newTimer) {
  return end == null || end.getTime().after(newTimer) || end.getTime().equals(newTimer);
}

代码示例来源:origin: apache/maven

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 ) )

相关文章