I need to calculate the difference in two times. I've created two calendars, one with the current time and one set to a specific time. I need to subtract them and calculate the difference in Months, days, hours, minutes, and seconds. I've been searching the web for a week now and I can't seem to find anything. Someone help please!!!
could you simple convert to millisecs the date and make a simple operation like long dif = date1.getTime() - date2.getTime() dif is the difference on milliseconds
Joined: May 06, 2003
This is the error I get when I try that: /tomcat/work/Standalone/#########_jsp.java:433: operator - cannot be applied to java.util.Date,java.util.Date long dif = AuctionCalendar.getTime() - calendar.getTime();
That's because the getTime() method of Calendar returns a Date, whose getTime() method returns the long value in msecs. So in order to convert a calendar to its msec equivalent you need to use something along the lines of:
hth, bear P.S. For future posts: this is a general Java question and should have been posted in the Java (Beginner) forum; just because you are trying to do this in a JSP doesn't make it a JSP question.