Link to home
Start Free TrialLog in
Avatar of opike
opike

asked on

Compare just time portion of calendar and date objects

In my code I have a date and a calendar object and I want to compare just the time portion. I'm thinking of doing something like this

public myfunc(Calendar cal1, Date date1)
{
   Calendar cal2 = (Calendar)cal1.clone();
   cal2.setTime(date1);
   if (cal2.after(cal1)
     <more code here...>
}

But I'm having trouble with the setTime() function since it also assigns the date info as well. So I need a setTime() that will only set the time.
ASKER CERTIFIED SOLUTION
Avatar of Mick Barry
Mick Barry
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of opike
opike

ASKER

Yeah...I guess I was struggling to hard to be more elegant.