當前位置: 首頁>>代碼示例>>Java>>正文


Java Date.compareTo方法代碼示例

本文整理匯總了Java中java.util.Date.compareTo方法的典型用法代碼示例。如果您正苦於以下問題:Java Date.compareTo方法的具體用法?Java Date.compareTo怎麽用?Java Date.compareTo使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.util.Date的用法示例。


在下文中一共展示了Date.compareTo方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: checkFecha

import java.util.Date; //導入方法依賴的package包/類
@Check
public void checkFecha(final Restaurante restaurante) {
  try {
    SimpleDateFormat formateadorFecha = new SimpleDateFormat("dd-MM-yyyy");
    Date fechaDada = formateadorFecha.parse(restaurante.getFecha());
    Calendar fechaActual = Calendar.getInstance();
    Date _time = fechaActual.getTime();
    boolean _greaterThan = (fechaDada.compareTo(_time) > 0);
    if (_greaterThan) {
      this.error("La fecha tiene que ser igual o menor que la actual", 
        RestaurantePackage.Literals.RESTAURANTE__FECHA, RestauranteValidator.FECHA_INVALIDA);
    }
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
開發者ID:vicegd,項目名稱:org.xtext.dsl.restaurante,代碼行數:17,代碼來源:RestauranteValidator.java

示例2: compareDatesString

import java.util.Date; //導入方法依賴的package包/類
public static int compareDatesString(String dateString, String anotherDateString, SimpleDateFormat simpleDateFormat) {
    final Date date;
    final Date anotherDate;
    try {
        date = simpleDateFormat.parse(dateString);
        anotherDate = simpleDateFormat.parse(anotherDateString);
    } catch (ParseException e) {
        throw new AssertionError("Incorrect date format" + e);
    }
    return date.compareTo(anotherDate);
}
 
開發者ID:WileyLabs,項目名稱:teasy,代碼行數:12,代碼來源:DateUtils.java

示例3: getModifiedAnnotation

import java.util.Date; //導入方法依賴的package包/類
@Override
public String getModifiedAnnotation() {
	if (userPermissionProfilesOut != null && userPermissionProfilesOut.size() > 0) {
		Long version = null;
		UserOutVO modifiedUser = null;
		Date modifiedTimestamp = null;
		Iterator<UserPermissionProfileOutVO> it = userPermissionProfilesOut.iterator();
		while (it.hasNext()) {
			UserPermissionProfileOutVO userPermissionProfilesOutVO = it.next();
			Date tagValueModifiedTimestamp = userPermissionProfilesOutVO.getModifiedTimestamp();
			if (modifiedTimestamp == null || (tagValueModifiedTimestamp != null && modifiedTimestamp.compareTo(tagValueModifiedTimestamp) < 0)) {
				modifiedUser = userPermissionProfilesOutVO.getModifiedUser();
				modifiedTimestamp = tagValueModifiedTimestamp;
			}
			if (version == null) {
				version = userPermissionProfilesOutVO.getVersion();
			} else {
				version = Math.max(version.longValue(), userPermissionProfilesOutVO.getVersion());
			}
		}
		if (version == null || modifiedUser == null || modifiedTimestamp == null) {
			return super.getModifiedAnnotation();
		} else {
			return WebUtil.getModifiedAnnotation(version.longValue(), modifiedUser, modifiedTimestamp);
		}
	} else {
		return super.getModifiedAnnotation();
	}
}
 
開發者ID:phoenixctms,項目名稱:ctsms,代碼行數:30,代碼來源:UserPermissionProfileBean.java

示例4: getRangeInMinutesForDay

import java.util.Date; //導入方法依賴的package包/類
/**
 * Get the amount of minutes for the event on a specific day. This is useful
 * if the event spans several days.
 *
 * @param targetDay
 *            The date to check
 * @return the amount of minutes for the event on a specific day. This is useful
 * if the event spans several days.
 */
public long getRangeInMinutesForDay(Date targetDay) {

    long rangeInMinutesForDay;

    // we must take into account that here can be not only 1 and 2 days, but
    // 1, 2, 3, 4... days first and last days - special cases all another
    // days between first and last - have range "ALL DAY"
    if (isTimeOnDifferentDays()) {
        if (targetDay.compareTo(getStart()) == 0) { // for first day
            rangeInMinutesForDay = DateConstants.DAYINMINUTES
                    - (getStartTime().getTime() - getStart().getTime())
                    / DateConstants.MINUTEINMILLIS;

        } else if (targetDay.compareTo(getEnd()) == 0) { // for last day
            rangeInMinutesForDay = (getEndTime().getTime()
                    - getEnd().getTime())
                    / DateConstants.MINUTEINMILLIS;

        } else { // for in-between days
            rangeInMinutesForDay = DateConstants.DAYINMINUTES;
        }
    } else { // simple case - period is in one day
        rangeInMinutesForDay = getRangeInMinutes();
    }
    return rangeInMinutesForDay;
}
 
開發者ID:blackbluegl,項目名稱:calendar-component,代碼行數:36,代碼來源:CalendarItem.java

示例5: compare

import java.util.Date; //導入方法依賴的package包/類
@Override
public int compare ( final ChangeEntry o1, final ChangeEntry o2 )
{
    final Date d1 = o1.getDate ();
    final Date d2 = o2.getDate ();
    if ( !this.invert )
    {
        return d1.compareTo ( d2 );
    }
    else
    {
        return -d1.compareTo ( d2 );
    }
}
 
開發者ID:eclipse,項目名稱:neoscada,代碼行數:15,代碼來源:ChangeEntryComparator.java

示例6: getExpired

import java.util.Date; //導入方法依賴的package包/類
private static Boolean getExpired(Date today, Date expiration) {
	if (today != null && expiration != null) {
		if (today.compareTo(expiration) > 0) {
			return true;
		} else {
			return false;
		}
	}
	return null;
}
 
開發者ID:phoenixctms,項目名稱:ctsms,代碼行數:11,代碼來源:WebUtil.java

示例7: compareDates

import java.util.Date; //導入方法依賴的package包/類
public static int compareDates(Object o1, Object o2) {
    Date d1 = DataUtil.parseDate(String.valueOf(o1));
    Date d2 = DataUtil.parseDate(String.valueOf(o2));
    if (d1 == null && d2 == null) {
        return 0;
    } else if (d1 == null) {
        return 1;
    } else if (d2 == null) {
        return -1;
    } else {
        return d2.compareTo(d1);
    }
}
 
開發者ID:Adobe-Consulting-Services,項目名稱:aem-epic-tool,代碼行數:14,代碼來源:DataUtil.java

示例8: Transactions

import java.util.Date; //導入方法依賴的package包/類
public Transactions(
        File inputJsonFile, Date minimumDate, Date maximumDate) throws IOException {
    JSONArray jsonArray = new JSONArray(
            FileUtils.readFileToString(inputJsonFile, StandardCharsets.UTF_8));

    for (int i = 0; i < jsonArray.length(); i++) {
        Transaction transaction = new Transaction(jsonArray.getJSONObject(i));
        final Date saleDate = transaction.getSaleDate();
        if (saleDate.compareTo(minimumDate) >= 0 && saleDate.compareTo(maximumDate) <= 0)
            transactions.add(transaction);
    }
}
 
開發者ID:BigBrassBand,項目名稱:remittanceparse,代碼行數:13,代碼來源:Transactions.java

示例9: isEventExpired

import java.util.Date; //導入方法依賴的package包/類
public boolean isEventExpired(){
    Calendar c = Calendar.getInstance();
    c.set(Calendar.HOUR_OF_DAY, 0);
    c.set(Calendar.MINUTE, 0);
    c.set(Calendar.SECOND, 0);
    c.set(Calendar.MILLISECOND, 0);

    Date date = c.getTime();
    return date.compareTo(eventDeadline) > 0;
}
 
開發者ID:wendyltan,項目名稱:EasyTodo,代碼行數:11,代碼來源:TodoEvent.java

示例10: getTodayFirstPosition

import java.util.Date; //導入方法依賴的package包/類
/**
 * 獲取當天提醒第一條記錄索引
 **/
@Override
public int getTodayFirstPosition() {
    for (int i = 0; i < showDatas.size(); i++) {
        Date rdate = showDatas.get(i).t.getRdate();
        if (rdate.compareTo(TimeUtils.getTodayDate()) >= 0
                && rdate.before(TimeUtils.getTomorrow())) {
            return i + 1;
        }
    }
    return -1;
}
 
開發者ID:LingjuAI,項目名稱:AssistantBySDK,代碼行數:15,代碼來源:RemindPresenter.java

示例11: compare

import java.util.Date; //導入方法依賴的package包/類
@Override
public int compare(CvPositionPDFVO a, CvPositionPDFVO b) {
	if (a != null && b != null) {
		CvSectionVO cvSectionA = a.getSection();
		CvSectionVO cvSectionB = b.getSection();
		if (cvSectionA != null && cvSectionB != null) {
			if (cvSectionA.getPosition() < cvSectionB.getPosition()) {
				return -1;
			} else if (cvSectionA.getPosition() > cvSectionB.getPosition()) {
				return 1;
			} else {
				Date dateA = (a.getStart() != null ? a.getStart() : a.getStop());
				Date dateB = (b.getStart() != null ? b.getStart() : b.getStop());
				if (dateA != null && dateB != null) {
					return dateA.compareTo(dateB);
				} else if (dateA == null && dateB != null) {
					return -1;
				} else if (dateA != null && dateB == null) {
					return 1;
				} else {
					return 0;
				}
			}
		} else if (cvSectionA == null && cvSectionB != null) {
			return -1;
		} else if (cvSectionA != null && cvSectionB == null) {
			return 1;
		} else {
			return 0;
		}
	} else if (a == null && b != null) {
		return -1;
	} else if (a != null && b == null) {
		return 1;
	} else {
		return 0;
	}
}
 
開發者ID:phoenixctms,項目名稱:ctsms,代碼行數:39,代碼來源:CvPositionPDFVOComparator.java

示例12: getWeek

import java.util.Date; //導入方法依賴的package包/類
protected int getWeek(Date date) {
    for (int idx=0;idx+1<iWeekDate.size();idx++)
        if (date.compareTo(iWeekDate.elementAt(idx))<0) return idx;
    return iWeekDate.size()-1;
}
 
開發者ID:Jenner4S,項目名稱:unitimes,代碼行數:6,代碼來源:MakeAssignmentsForClassEvents.java

示例13: findPosition

import java.util.Date; //導入方法依賴的package包/類
private long findPosition(File file, Date date) throws IOException {
	RandomAccessFile raf = new RandomAccessFile(file, "r");
	
	try {
		Date cur_date = extractDate(raf);
		if (cur_date != null) {
			int compare = date.compareTo(cur_date);
			if (compare > 0) {
				date.setTime(date.getTime() - 1);
				long min = raf.getFilePointer();
				long max = raf.length();
				Date last_date = null;
				long last_pos = 0;
				while (cur_date != null && !cur_date.equals(last_date) && !cur_date.equals(date)) {
					last_date = cur_date;
					last_pos = raf.getFilePointer();
					long cur = min + ((max - min) / 2);
					raf.seek(cur);
					cur_date = extractDate(raf);
					if (cur_date == null || date.compareTo(cur_date) < 0) {
						max = cur;
					} else {
						min = cur;
					}
				}
				date.setTime(date.getTime() + 1);
				
				if (cur_date != null && date.compareTo(cur_date) < 0) {
					raf.seek(min);
					cur_date = extractDate(raf);
				}
				
				// Fix #1788 : 'Out of range Date' exception when start date is 2011-01-25 12:32 for log file of #1787
				// can find next cur_date but last_date is a valid candidate for the end date
				if (cur_date == null && last_date != null) {
					cur_date = last_date;
					raf.seek(last_pos);
				}
				while (cur_date != null && date.compareTo(cur_date) > 0) {
					raf.skipBytes(1);
					cur_date = extractDate(raf);
				}
			}
			if (cur_date != null) {
				return raf.getFilePointer();
			}
		}
		throw new IOException("Out of range Date");
	} finally {
		raf.close();
	}
}
 
開發者ID:convertigo,項目名稱:convertigo-engine,代碼行數:53,代碼來源:TemporalInputStream.java

示例14: future

import java.util.Date; //導入方法依賴的package包/類
/** 未來某一天 */
public static void future(Date date, String key) {
	if (date != null && date.compareTo(new Date()) <= 0) {
		throw new IllegalArgumentException(getMessage(key + "_NOT_FUTURE"));
	}
}
 
開發者ID:tb544731152,項目名稱:iBase4J,代碼行數:7,代碼來源:Assert.java

示例15: isGreaterEqual

import java.util.Date; //導入方法依賴的package包/類
/** Returns true if the date d1 is greater than date d1 or both are equal */
public static boolean isGreaterEqual(Date d1, Date d2) {
	return isEqual(d1, d2) || d1 != null && d1.compareTo(d2) > 0;
}
 
開發者ID:transwarpio,項目名稱:rapidminer,代碼行數:5,代碼來源:Tools.java


注:本文中的java.util.Date.compareTo方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。