List of utility methods to do Date Compare
int | compare(final Date lhs, final Date rhs) Null-safe implementation to compare two dates against each other. if (lhs == null) return (rhs == null ? 0 : -1); if (lhs == rhs) return 0; if (rhs == null) return 1; return lhs.compareTo(rhs); |
Integer | compare(final Date one, final Date another) compare if (one == null || another == null) { return null; final Calendar cal1 = Calendar.getInstance(); final Calendar cal2 = Calendar.getInstance(); cal1.setTime(one); cal2.setTime(another); int age = Math.abs(cal1.get(Calendar.YEAR) - cal2.get(Calendar.YEAR)); ... |
int | compare2Date(Date date1, Date date2) |
int | compare2Dates(Date d1, Date d2) Compare two days and returns -1 if d1 is less than d2 0 if both are equal, 1 if d1 is greater than d2 Calendar c1 = Calendar.getInstance(); Calendar c2 = Calendar.getInstance(); c1.setTime(d1); c2.setTime(d2); if (c1.before(c2)) { return -1; } else if (c1.after(c2)) { return 1; ... |
int | compare2DateString(String DateStringType, String dateStr1, String dateStr2) compare Date String try { SimpleDateFormat df = new SimpleDateFormat(DateStringType); Date d1 = df.parse(dateStr1); Date d2 = df.parse(dateStr2); if (d1.after(d2)) { return 0; } else if (d1.equals(d2)) { return 1; ... |
int | compare_date2(String finalDate, String enddate) compardate try { DateFormat df = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); Date d1 = df.parse(finalDate); Date d2 = df.parse(enddate); int ss = d1.compareTo(d2); return ss; } catch (ParseException e) { e.printStackTrace(); ... |
int | compareCalendars(Date fechaAComparar, Date fechaBase) compare Calendars Calendar calendario1 = Calendar.getInstance(); calendario1.setTime(fechaAComparar); Calendar calendario2 = Calendar.getInstance(); calendario2.setTime(fechaBase); if (calendario1.get(Calendar.YEAR) == calendario2.get(Calendar.YEAR) && calendario1.get(Calendar.MONTH) == calendario2.get(Calendar.MONTH) && calendario1.get(Calendar.DATE) == calendario2.get(Calendar.DATE)) { return 0; ... |
int | compareDate(Date d1, Date d2) Compares two dates. if (d1 == null && d2 == null) return 0; if (d1 == null && d2 != null) return -1; if (d1 != null && d2 == null) return 1; Calendar c1 = Calendar.getInstance(); c1.setTime(d1); ... |
int | compareDate(Date d1, Date d2) tra ve 1 neu date1 sau date2 int result = 0;
Calendar cal1 = Calendar.getInstance();
Calendar cal2 = Calendar.getInstance();
cal1.setTime(d1);
cal1.set(Calendar.HOUR_OF_DAY, 0);
cal1.set(Calendar.MINUTE, 0);
cal1.set(Calendar.SECOND, 0);
cal1.set(Calendar.MILLISECOND, 0);
...
|
boolean | compareDate(Date d1, Date d2) compare Date Calendar c1 = Calendar.getInstance(); Calendar c2 = Calendar.getInstance(); c1.setTime(d1); c2.setTime(d2); int result = c1.compareTo(c2); if (result > 0) return true; else ... |