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

x33g5p2x  于2022-01-17 转载在 其他  
字(9.8k)|赞(0)|评价(0)|浏览(171)

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

Calendar.after介绍

[英]Returns whether the Date represented by this Calendar instance is after the Daterepresented by the parameter. The comparison is not dependent on the time zones of the Calendar.
[中]返回此日历实例表示的日期是否在参数表示的日期之后。比较不依赖于日历的时区。

代码示例

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

Calendar cal1 = Calendar.getInstance();
     Calendar cal2 = Calendar.getInstance();
     cal1.setTime(date1);
     cal2.setTime(date2);
     if(cal1.after(cal2)){
       System.out.println("Date1 is after Date2");
     }
     if(cal1.before(cal2)){
       System.out.println("Date1 is before Date2");
     }
     if(cal1.equals(cal2)){
       System.out.println("Date1 is equal Date2");
     }

代码示例来源:origin: org.testng/testng

@Override
public boolean isSkip() {
 if (null == m_expireDate) {
  return false;
 }
 try {
  Calendar now= Calendar.getInstance();
  Date nowDate= m_inFormat.parse(m_inFormat.format(now.getTime()));
  now.setTime(nowDate);
  return !now.after(m_expireDate);
 }
 catch(ParseException pex) {
  throw new TestNGException("Cannot compare dates.");
 }
}

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

Calendar start = Calendar.getInstance();
start.setTime(startDate);

Calendar end = Calendar.getInstance();
end.setTime(endDate);

while( !start.after(end)){
  Date targetDay = start.getTime();
  // Do Work Here

  start.add(Calendar.DATE, 1);
}

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

Calendar myBirthDate = Calendar.getInstance();
myBirthDate.clear();
myBirthDate.set(1978, 3 - 1, 26);
Calendar now = Calendar.getInstance();
Calendar clone = (Calendar) myBirthDate.clone(); // Otherwise changes are been reflected.
int years = -1;
while (!clone.after(now)) {
  clone.add(Calendar.YEAR, 1);
  years++;
}
System.out.println(years); // 32

代码示例来源:origin: wiztools/rest-client

@Override
  public void actionPerformed(ActionEvent e) {
    Calendar c = (Calendar)statusLastUpdated.clone();
    c.add(Calendar.SECOND, 20);
    if(Calendar.getInstance().after(c)){
      setStatus(RCConstants.TITLE);
    }
  }
}).start();

代码示例来源:origin: jenkinsci/jenkins

@Restricted(NoExternalUse.class) // just for form validation
public @CheckForNull Calendar next() {
  Calendar nearest = null;
  for (CronTab tab : tabs) {
    Calendar scheduled = tab.ceil(tab.getTimeZone() == null ? Calendar.getInstance() : Calendar.getInstance(tab.getTimeZone()));
    if (nearest == null || nearest.after(scheduled)) {
      nearest = scheduled;
    }
  }
  return nearest;
}

代码示例来源:origin: cbeust/testng

@Override
public boolean isSkip() {
 if (null == m_expireDate) {
  return false;
 }
 try {
  Calendar now = Calendar.getInstance();
  Date nowDate = m_inFormat.parse(m_inFormat.format(now.getTime()));
  now.setTime(nowDate);
  return !now.after(m_expireDate);
 } catch (ParseException pex) {
  throw new TestNGException("Cannot compare dates.");
 }
}

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

Calendar now = Calendar.getInstance();
Calendar dob = Calendar.getInstance();
dob.setTime(...);
if (dob.after(now)) {
 throw new IllegalArgumentException("Can't be born in the future");
}
int year1 = now.get(Calendar.YEAR);
int year2 = dob.get(Calendar.YEAR);
int age = year1 - year2;
int month1 = now.get(Calendar.MONTH);
int month2 = dob.get(Calendar.MONTH);
if (month2 > month1) {
 age--;
} else if (month1 == month2) {
 int day1 = now.get(Calendar.DAY_OF_MONTH);
 int day2 = dob.get(Calendar.DAY_OF_MONTH);
 if (day2 > day1) {
  age--;
 }
}
// age is now correct

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

private static List<Date> getDates(String dateString1, String dateString2)
{
  ArrayList<Date> dates = new ArrayList<Date>();
  DateFormat df1 = new SimpleDateFormat("yyyy-MM-dd");

  Date date1 = null;
  Date date2 = null;

  try {
    date1 = df1 .parse(dateString1);
    date2 = df1 .parse(dateString2);
  } catch (ParseException e) {
    e.printStackTrace();
  }

  Calendar cal1 = Calendar.getInstance();
  cal1.setTime(date1);

  Calendar cal2 = Calendar.getInstance();
  cal2.setTime(date2);

  while(!cal1.after(cal2))
  {
    dates.add(cal1.getTime());
    cal1.add(Calendar.DATE, 1);
  }
  return dates;
}

代码示例来源:origin: glyptodon/guacamole-client

/**
 * Given a time when a particular state changes from inactive to active,
 * and a time when a particular state changes from active to inactive,
 * determines whether that state is currently active.
 *
 * @param activeStart
 *     The time at which the state changes from inactive to active.
 *
 * @param inactiveStart
 *     The time at which the state changes from active to inactive.
 *
 * @return
 *     true if the state is currently active, false otherwise.
 */
private boolean isActive(Calendar activeStart, Calendar inactiveStart) {
  // If end occurs before start, convert to equivalent case where start
  // start is before end
  if (inactiveStart != null && activeStart != null && inactiveStart.before(activeStart))
    return !isActive(inactiveStart, activeStart);
  // Get current time
  Calendar current = Calendar.getInstance();
  // State is active iff the current time is between the start and end
  return !(activeStart != null && current.before(activeStart))
    && !(inactiveStart != null && current.after(inactiveStart));
}

代码示例来源:origin: apache/incubator-gobblin

Calendar windowStartTime = Calendar.getInstance();
windowStartTime.set(Calendar.HOUR_OF_DAY, windowStartHour);
windowStartTime.set(Calendar.MINUTE, 0);
windowStartTime.set(Calendar.SECOND, 0);
Calendar windowEndTime = Calendar.getInstance();
windowEndTime.set(Calendar.HOUR_OF_DAY, windowEndHour);
windowEndTime.set(Calendar.MINUTE, 0);
Calendar now = Calendar.getInstance();
if (now.after(windowStartTime) && now.before(windowEndTime)) {

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

public int getAge() {
 Calendar now = Calendar.getInstance();
 Calendar bd = Calendar.getInstance();
 bd.setTime(_birthdate);
 Calendar bdThisYear = Calendar.getInstance();
 bdThisYear.setTime(_birthdate);
 bdThisYear.set(Calendar.YEAR, now.get(Calendar.YEAR));
 int age = now.get(Calendar.YEAR) - bd.get(Calendar.YEAR);
 if (bdThisYear.after(now))
  age--;
 return age;
}

代码示例来源:origin: apache/incubator-gobblin

private boolean isWithinWindow(int windowStartInHours, int windowEndInHours, String outputScheduledString)
   throws ParseException {
  Calendar windowStart = Calendar.getInstance();
  windowStart.set(Calendar.HOUR_OF_DAY, windowStartInHours);
  windowStart.set(Calendar.MINUTE, 0);
  windowStart.set(Calendar.SECOND, 0);

  Calendar windowEnd = Calendar.getInstance();
  windowEnd.set(Calendar.HOUR_OF_DAY, windowEndInHours);
  windowEnd.set(Calendar.MINUTE, 0);
  windowEnd.set(Calendar.SECOND, 0);

  Date outputDate = new SimpleDateFormat("hh,mm,a,z").parse(outputScheduledString);
  Calendar receivedTime = Calendar.getInstance();
  receivedTime.set(Calendar.HOUR_OF_DAY, Integer.parseInt(new SimpleDateFormat("HH").format(outputDate)));
  receivedTime.set(Calendar.MINUTE, Integer.parseInt(new SimpleDateFormat("mm").format(outputDate)));

  log.info("Window start time is: " + new SimpleDateFormat("MM/dd/yyyy hh,mm,a,z").format(windowStart.getTime()));
  log.info("Window end time is: " + new SimpleDateFormat("MM/dd/yyyy hh,mm,a,z").format(windowEnd.getTime()));
  log.info("Output time is: " + new SimpleDateFormat("MM/dd/yyyy hh,mm,a,z").format(receivedTime.getTime()));

  return receivedTime.after(windowStart) && receivedTime.before(windowEnd);
 }
}

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

Calendar today = Calendar.getInstance();
Calendar birthDate = Calendar.getInstance();
if (birthDate.after(today)) {
  throw new IllegalArgumentException("Can't be born in the future");

代码示例来源:origin: javahongxi/whatsmars

/**
 * 计算两个日期之间相隔的月份
 *
 * @param startDate
 * @param endDate
 * @return
 */
public static List<String> intervalMonths(Date startDate, Date endDate) {
  List<String> monthList = new ArrayList<String>();
  Calendar tmp = Calendar.getInstance();
  tmp.setTime(startDate);
  tmp.set(Calendar.DAY_OF_MONTH, tmp.getActualMaximum(Calendar.DAY_OF_MONTH) - 1);
  Calendar start = Calendar.getInstance();
  start.setTime(startDate);
  start.set(Calendar.DAY_OF_MONTH, 1);
  Calendar end = Calendar.getInstance();
  end.setTime(endDate);
  end.set(Calendar.DAY_OF_MONTH, end.getActualMaximum(Calendar.DAY_OF_MONTH));
  SimpleDateFormat sdf = new SimpleDateFormat(DATE_SHORT_FORMAT);
  for (; tmp.after(start) && tmp.before(end); tmp.add(Calendar.MONTH, 1), tmp.set(Calendar.DAY_OF_MONTH, tmp.getActualMaximum(Calendar.DAY_OF_MONTH) - 1)) {
    monthList.add(sdf.format(tmp.getTime()));
  }
  return monthList;
}

代码示例来源:origin: bill1012/AdminEAP

int flag = 0;
try {
  Calendar objCalendarDate1 = Calendar.getInstance();
  objCalendarDate1.setTime(fromDate);
  Calendar objCalendarDate2 = Calendar.getInstance();
  objCalendarDate2.setTime(toDate);
  if (objCalendarDate1.after(objCalendarDate2)) {
    Calendar temp = objCalendarDate1;
    objCalendarDate1 = objCalendarDate2;

代码示例来源:origin: bill1012/AdminEAP

int flag = 0;
try {
  Calendar objCalendarDate1 = Calendar.getInstance();
  objCalendarDate1.setTime(DateFormat.getDateInstance().parse(strDate1));
  Calendar objCalendarDate2 = Calendar.getInstance();
  objCalendarDate2.setTime(DateFormat.getDateInstance().parse(strDate2));
  if (objCalendarDate1.after(objCalendarDate2)) {
    Calendar temp = objCalendarDate1;
    objCalendarDate1 = objCalendarDate2;

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

for (SimpleDateFormat pattern : validPatterns) {
  try {
    Calendar cal = Calendar.getInstance();
    cal.setTime(pattern.parse(candidate));
    Calendar current = Calendar.getInstance();
    if (cal.get(Calendar.YEAR) == 1970) {
      cal.set(Calendar.YEAR, current.get(Calendar.YEAR));
    if (cal.after(current)) {
      cal.add(Calendar.YEAR, -1);

代码示例来源:origin: jwpttcg66/NettyGameServer

Calendar st = Calendar.getInstance();
st.setTimeInMillis(time1);
Calendar now = Calendar.getInstance();
now.setTimeInMillis(time2);
Calendar spec = Calendar.getInstance();
spec.setTimeInMillis(specTime);
if(st.after(st_spec))

代码示例来源:origin: org.drools/drools-core

@Test
public void testDateEffective() {
  WorkingMemory wm = (WorkingMemory) new KnowledgeBaseImpl( "x", null).newKieSession();
  final RuleImpl rule = new RuleImpl( "myrule" );
  assertTrue( rule.isEffective(null, new RuleTerminalNode(), wm ) );
  final Calendar earlier = Calendar.getInstance();
  earlier.setTimeInMillis( 10 );
  rule.setDateEffective( earlier );
  assertTrue( rule.isEffective(null, new RuleTerminalNode(), wm ) );
  final Calendar later = Calendar.getInstance();
  later.setTimeInMillis( later.getTimeInMillis() + 100000000 );
  assertTrue( later.after( Calendar.getInstance() ) );
  rule.setDateEffective( later );
  assertFalse( rule.isEffective(null, new RuleTerminalNode(), wm ) );
}

相关文章