Re: Date comparisons
- From: Arne Vajhøj <arne@xxxxxxxxxx>
- Date: Sun, 14 Mar 2010 22:29:44 -0400
On 12-03-2010 11:12, laredotornado wrote:
I'm using Java 1.5. I have a java.util.Date object and I would like
to determine if it's date (i.e. year, month, and day) are greater than
(in the future) or equal to today's date (year, month, and day).
However, I don't care about any time component (hour, minute,
second ...) when the comparison is taking place. What is the easiest
way I can determine this?
There must be several ways.
My suggestion:
public static boolean isFutureDay(Date d) {
Calendar cal = Calendar.getInstance();
cal.setTime(d);
Calendar fut = Calendar.getInstance();
fut.add(Calendar.DATE, 1);
fut.set(Calendar.HOUR_OF_DAY, 0);
fut.set(Calendar.MINUTE, 0);
fut.set(Calendar.SECOND, 0);
fut.set(Calendar.MILLISECOND, 0);
return cal.compareTo(fut) >= 0;
}
Arne
.
- References:
- Date comparisons
- From: laredotornado
- Date comparisons
- Prev by Date: Re: First class developer: who ?
- Next by Date: Re: First class developer: who ?
- Previous by thread: Re: Date comparisons
- Next by thread: Cheeps Guest houses Karachi Independents fully furnished
- Index(es):