List of utility methods to do Time Compare
boolean | isEarilerDate(Time t1, Time t2) is Eariler Date if (t1.year != t2.year) { return t1.year < t2.year; if (t1.month != t2.month) { return t1.month < t2.month; return t1.monthDay < t2.monthDay; |
boolean | isPastDateTime(DateTime target) is Past Date Time boolean bPast = false; Calendar targetCal = getCalFromDateTime(target); Calendar currentCal = Calendar.getInstance(); if (currentCal.compareTo(targetCal) > 0) { bPast = true; return bPast; |
boolean | isSameDate(Time t1, Time t2) is Same Date return (t1.monthDay == t2.monthDay) && (t1.month == t2.month)
&& (t1.year == t2.year);
|
boolean | isSameLocalTime(Calendar cal1, Calendar cal2) Checks if two calendar objects represent the same local time. This method compares the values of the fields of the two objects. if (cal1 == null || cal2 == null) { throw new IllegalArgumentException("The date must not be null"); return (cal1.get(Calendar.MILLISECOND) == cal2 .get(Calendar.MILLISECOND) && cal1.get(Calendar.SECOND) == cal2.get(Calendar.SECOND) && cal1.get(Calendar.MINUTE) == cal2.get(Calendar.MINUTE) && cal1.get(Calendar.HOUR_OF_DAY) == cal2 ... |
boolean | isSameMonth(Time t1, Time t2) is Same Month return (t1.month == t2.month) && (t1.year == t2.year);
|
int | isTimeAfter(String webTime, String localTime) is Time After SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Date serverTime = null; Date deviceTime = null; try { serverTime = sdf.parse(webTime); deviceTime = sdf.parse(localTime); } catch (ParseException e) { e.printStackTrace(); ... |
boolean | isOnRange(String fromTime, String toTime) is On Range DateFormat dateFormat = new SimpleDateFormat("h:mm a"); try { Date date1, date2, dateNueva; date1 = dateFormat.parse(fromTime); date2 = dateFormat.parse(toTime); String now = dateFormat.format(new Date()); dateNueva = dateFormat.parse(now); if ((date1.compareTo(dateNueva) <= 0) ... |
long | javaToDosTime(long time) Converts input time from Java to DOS format Calendar cal = Calendar.getInstance(); cal.setTimeInMillis(time); int year = cal.get(Calendar.YEAR); if (year < 1980) { return (1 << 21) | (1 << 16); return (year - 1980) << 25 | (cal.get(Calendar.MONTH) + 1) << 21 | cal.get(Calendar.DATE) << 16 ... |
long | timeEnd(String tag, long threshold) time End Long old = times.get(tag); if (old == null) return 0; long now = System.currentTimeMillis(); long diff = now - old; if (threshold == 0 || diff > threshold) { debug(tag, diff); return diff; |