Prev: Open popup from JSP - Servlet ??
Next: XPath question.
From: Roedy Green on 12 Mar 2010 15:42 On Fri, 12 Mar 2010 08:12:03 -0800 (PST), laredotornado <laredotornado(a)zipmail.com> wrote, quoted or indirectly quoted someone who said : >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? 1. use BigDate. see http://mindprod.com/products1.html#BIGDATE 2. extract the long timestamp from each date. Divide by the number of milliseconds in a day to get days since 1970. Compare those, keeping in mind these are UTC days. Christmas in Moscow may compare different from Christmas in Toledo. for background see http://mindprod.com/jgloss/calendar.html http://mindprod.com/jgloss/time.html http://mindprod.com/jgloss/date.html -- Roedy Green Canadian Mind Products http://mindprod.com The first 90% of the code accounts for the first 90% of the development time. The remaining 10% of the code accounts for the other 90% of the development time. ~ Tom Cargill
From: Lew on 12 Mar 2010 16:12 On Mar 12, 11:12 am, laredotornado <laredotorn...(a)zipmail.com> wrote: > Hi, > > 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? Use Calendar. Normalize to the same time zone. Zero out the time portion (using 'set()', *not* 'clear()'!). Compare using 'after()' or 'before()'. Read the Javadocs. -- Lew
From: Lew on 12 Mar 2010 16:14 Roedy Green wrote: > 2. extract the long timestamp from each date. Divide by the number of > milliseconds in a day to get days since 1970. Compare those, keeping > in mind these are UTC days. Christmas in Moscow may compare different > from Christmas in Toledo. That will have troubles this weekend in my part of the world, i.e., give the wrong answer. The number of milliseconds in a day depends on the date. -- Lew
From: Roedy Green on 12 Mar 2010 22:07 On Fri, 12 Mar 2010 13:14:11 -0800 (PST), Lew <lew(a)lewscanon.com> wrote, quoted or indirectly quoted someone who said : >That will have troubles this weekend in my part of the world, i.e., >give the wrong answer. > >The number of milliseconds in a day depends on the date. I have long railed against DST as a nutty idea. http://mindprod.com/jgloss/dst.html The Rachael Maddow show trashed it tonight. It turns out it does not save energy. With the extra evening hours people drive to the mall or ballpark. It is a retail stimulus and a way to increase gas consumption. The story is we do it for the farmers. They strenuously opposed it when it was introduced. It gave them one less hour before the city markets opened. I wonder how many people have been killed by the anomalies when the time changes. I could imagine some incompetent maker of medical pumps giving a double dose, or skipping a dose. I think anyone who has to co-ordinate should be tracking time in UTC. But even then data entry still happens in local time. -- Roedy Green Canadian Mind Products http://mindprod.com The first 90% of the code accounts for the first 90% of the development time. The remaining 10% of the code accounts for the other 90% of the development time. ~ Tom Cargill
From: Roedy Green on 12 Mar 2010 22:22 On Fri, 12 Mar 2010 12:42:32 -0800, Roedy Green <see_website(a)mindprod.com.invalid> wrote, quoted or indirectly quoted someone who said : > >1. use BigDate. see http://mindprod.com/products1.html#BIGDATE BigDate from = new BigDate( 2010, 2, 28); BigDate to = new BigDate ( 2010, 3, 12 ); int diff = to.compareTo( from ); Or starting with a timestamp in the form of a UTC Date and a TimeZone BigDate from = new BigDate( dateFrom, tzFrom ); BigDate to = new BigDate ( dateTo, tzTo ); int diff = to.compareTo( from ); -- Roedy Green Canadian Mind Products http://mindprod.com The first 90% of the code accounts for the first 90% of the development time. The remaining 10% of the code accounts for the other 90% of the development time. ~ Tom Cargill
First
|
Prev
|
Next
|
Last
Pages: 1 2 3 4 Prev: Open popup from JSP - Servlet ?? Next: XPath question. |