Finding Date Difference

M

Mick

There must be an 'easy' way to find the difference between 2 dates

ie.

thisDate_1 = new java.util.Date(strStartDate);
thisDate_2 = new java.util.Date(strEndDate);

thisDateDiff = thisDate_2 - thisDate_1 ????
 
M

Mick

Thanks...but

Why does this not compile??

Calendar thisCal_1 = Calendar.getInstance();
thisDate_1 = new java.util.Date(strStartDate);
thisCal_1.setTime(thisDate_1);

Mick
 
A

Andrew Thompson

On Thu, 02 Dec 2004 18:31:26 GMT, Mick wrote:

Please refrain form top-posting Mick, I find it nost confusing..
Why does this not compile??

Calendar thisCal_1 = Calendar.getInstance();
thisDate_1 = new java.util.Date(strStartDate);
thisCal_1.setTime(thisDate_1);

That would depend on the compilation errors, which are a lot more
specific than 'not compile' amd actually reference line numbers.
<http://www.physci.org/codes/javafaq.jsp#exact>

Check especially the links to 'compile time' error messages at
the end of that section.

HTH
 
T

Thomas Fritsch

Mick said:
Thanks...but

Why does this not compile??

Calendar thisCal_1 = Calendar.getInstance();
thisDate_1 = new java.util.Date(strStartDate);
thisDate_1 is assigned a Date object ...
thisCal_1.setTime(thisDate_1);
.... but setTime(...) expects a long.
I could set a link to the javadoc of Date#setTime here, but I don't ;-)

Thomas
 
T

Thomas Fritsch

Thomas said:
thisDate_1 is assigned a Date object ...


... but setTime(...) expects a long.
I could set a link to the javadoc of Date#setTime here, but I don't ;-)
Sorry, my answer was wrong.
I confused Date#setTime with Calendar#setTime
 
M

Mick

Andrew Thompson said:
On Thu, 02 Dec 2004 18:31:26 GMT, Mick wrote:

Please refrain form top-posting Mick, I find it nost confusing..


That would depend on the compilation errors, which are a lot more
specific than 'not compile' amd actually reference line numbers.
<http://www.physci.org/codes/javafaq.jsp#exact>

Check especially the links to 'compile time' error messages at
the end of that section.


C:\....._jsp.java:35: expected
thisCal_1.setTime(thisDate_1);
^
1 error

The 'arrow' is actually under the opening bracket (

Mick
 
T

Thomas Fritsch

Mick said:
Thanks...but

Why does this not compile??

Calendar thisCal_1 = Calendar.getInstance();
thisDate_1 = new java.util.Date(strStartDate);
thisCal_1.setTime(thisDate_1);
Exactly which line does not compile? What did the compiler say?
 
A

Andrew Thompson

Did you read *all* of that link Mick? There were further tips to
prompt you to trim content no longer relevant.
 
J

Jacob

Mick said:
There must be an 'easy' way to find the difference between 2 dates

No there isn't. You can find the difference between two
moments in time, but make sure the two are represented
by Calendars of the same reference (i.e. TimeZone).
The difference is measured in milliseconds so it still
takes some effort to convert it to something useful
depending on your context.

In an attempt to make it easier to work with *dates* (as
opposed to *times*) I wrote the Day.java class:

http://geosoft.no/software/day/Day.java.html

In particluar, note the Day.daysBetween() method.
 
T

Tim Ward

Jacob said:
No there isn't. You can find the difference between two
moments in time, but make sure the two are represented
by Calendars of the same reference (i.e. TimeZone).
The difference is measured in milliseconds so it still
takes some effort to convert it to something useful
depending on your context.

Oh yes, this is a fun problem regardless of language. Compare a date in July
with one in December - depending on where you live there's likely to be an
odd hour in the difference, because of seasonal clock changes, which can
really srew things up if you're not expecting it.
 
M

Mick

Andrew Thompson said:
...

expected ..what exactly? The compiler is usually more specific.

Yes it is but in this case that is all it had for 'expected'.

There was also this:

org.apache.jasper.JasperException: Unable to compile class for JSP

An error occurred at line: -1 in the jsp file: null

Generated servlet error:
[javac] Compiling 1 source file

Mick
 
A

Andrew Thompson

Andrew Thompson said:
...

expected ..what exactly? The compiler is usually more specific.

Yes it is but in this case that is all it had for 'expected'.

There was also this:

org.apache.jasper.JasperException: Unable to compile class for JSP

An error occurred at line: -1 in the jsp file: null

Generated servlet error:
[javac] Compiling 1 source file

Aha! I suspect that is the *cause* if the problem.
Does it occur before or after the 'expected' error?

And Mick, if I might bug you for one more thing? Please
trim 'sigs.'*, as well as any material that is no longer
needed in a thread.

* These things do not need to be quoted.
</trim>
 
M

Mick

C:\....._jsp.java:35: expected
expected ..what exactly? The compiler is usually more specific.

Yes it is but in this case that is all it had for 'expected'.

There was also this:

org.apache.jasper.JasperException: Unable to compile class for JSP

An error occurred at line: -1 in the jsp file: null

Generated servlet error:
[javac] Compiling 1 source file

Aha! I suspect that is the *cause* if the problem.
Does it occur before or after the 'expected' error?
This output was before the 'expected' error.

Mick
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,577
Members
45,052
Latest member
LucyCarper

Latest Threads

Top