Re: Comparing time
In article
<bac1d16f-1473-429b-9d81-358184f02b55@t54g2000hsg.googlegroups.com>,
mike <mikaelpetterson@hotmail.com> wrote:
[...]
How can I compare time without using any date information?
You can't; you have specified that myMethod() uses a Date. I assume you
meant java.util.Date. Use before(), after(), equals() or compareTo().
You may need to specify a TimeZone and Locale in getInstance().
For example,
public boolean myMethod (Date date) {
Calendar myDate = Calendar.getInstance();
myDate.setTime(date);
Calendar time1 = (Calendar) myDate.clone();
time1.set(Calendar.HOUR_OF_DAY, 7);
time1.set(Calendar.MINUTE, 59);
time1.set(Calendar.SECOND, 59);
time1.set(Calendar.MILLISECOND, 999);
Calendar time2 = (Calendar) myDate.clone();
time2.set(Calendar.HOUR_OF_DAY, 17);
time2.set(Calendar.MINUTE, 0);
time2.set(Calendar.SECOND, 0);
time2.set(Calendar.MILLISECOND, 1);
return (myDate.after(time1) && myDate.before(time2));
}
[not tested]
--
John B. Matthews
trashgod at gmail dot com
home dot woh dot rr dot com slash jbmatthews