Re: Simple date compare
Andrea Francia wrote:
Roedy Green wrote:
On Sun, 9 Mar 2008 00:53:15 -0800 (PST), Ulf <ulf.hemma@gmail.com>
wrote, quoted or indirectly quoted someone who said :
Can anyone please help me with a simple solution?
1. use BigDate. see http://mindprod.com/products1.html#COMMON11
2. get the timestamp long, and divide by the number of milliseconds in
a day to get the day number in GMT.
This is not safe, it will not take in account the leap second.
3. as 2, but adjust by timezone offset in millis first to get local
date.
The OP's only objection to the Calendar class is
Using Calendar would be possible, but adds a lot of code.
In other words, laziness, even if it were true, which it isn't.
Calendar lets one zero out the time fields, leaving only the date fields filled.
Calendar cal = Calendar.getInstance();
cal.set( Calendar.HOUR, 0 );
cal.set( Calendar.MINUTE, 0 );
cal.set( Calendar.SECOND, 0 );
cal.set( Calendar.MILLISECOND, 0 );
It lets you directly compare one instance to another, using
<http://java.sun.com/javase/6/docs/api/java/util/Calendar.html#compareTo(java.util.Calendar)>
That's going to be a lot less code and a lot more direct than messing with
milliseconds and timezone calculations. This time laziness is steering you in
the direction of *more* work, not less.
--
Lew