Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Finding Date Difference

Reply
Thread Tools

Finding Date Difference

 
 
Mick
Guest
Posts: n/a
 
      12-02-2004
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 ????



--
Mick


 
Reply With Quote
 
 
 
 
Thomas Fritsch
Guest
Posts: n/a
 
      12-02-2004
Mick wrote:
> 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 ????
>

long thisDateDiff = thisDate_2.getTime() - thisDate_1.getTime();
....as always javadoc is your friend:
<http://java.sun.com/j2se/1.4.2/docs/api/java/util/Date.html#getTime()>

--
"Thomas:Fritsch$ops:de".replace(':','.').replace(' $','@')

 
Reply With Quote
 
 
 
 
Mick
Guest
Posts: n/a
 
      12-02-2004
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

"Thomas Fritsch" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Mick wrote:
> > 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 ????
> >

> long thisDateDiff = thisDate_2.getTime() - thisDate_1.getTime();
> ...as always javadoc is your friend:
> <http://java.sun.com/j2se/1.4.2/docs/api/java/util/Date.html#getTime()>
>
> --
> "Thomas:Fritsch$ops:de".replace(':','.').replace(' $','@')
>



 
Reply With Quote
 
Andrew Thompson
Guest
Posts: n/a
 
      12-02-2004
On Thu, 02 Dec 2004 18:31:26 GMT, Mick wrote:

Please refrain form top-posting Mick, I find it nost confusing..
<http://www.physci.org/codes/javafaq.jsp#netiquette>

> 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

--
Andrew Thompson
http://www.PhySci.org/codes/ Web & IT Help
http://www.PhySci.org/ Open-source software suite
http://www.1point1C.org/ Science & Technology
http://www.LensEscapes.com/ Images that escape the mundane
 
Reply With Quote
 
Thomas Fritsch
Guest
Posts: n/a
 
      12-02-2004
Mick wrote:

> 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
>
> Mick


Thomas
--
"Thomas:Fritsch$ops:de".replace(':','.').replace(' $','@')

 
Reply With Quote
 
Thomas Fritsch
Guest
Posts: n/a
 
      12-02-2004
Thomas Fritsch wrote:
> Mick wrote:
>
>> 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

Sorry, my answer was wrong.
I confused Date#setTime with Calendar#setTime
>
>>
>> Mick

>
>
> Thomas



--
"Thomas:Fritsch$ops:de".replace(':','.').replace(' $','@')

 
Reply With Quote
 
Mick
Guest
Posts: n/a
 
      12-02-2004
"Andrew Thompson" <(E-Mail Removed)> wrote in message
news:11bf4k4qo9jbh$(E-Mail Removed).. .
> On Thu, 02 Dec 2004 18:31:26 GMT, Mick wrote:
>
> Please refrain form top-posting Mick, I find it nost confusing..
> <http://www.physci.org/codes/javafaq.jsp#netiquette>
>
> > 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.



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

The 'arrow' is actually under the opening bracket (

Mick


>
> HTH
>
> --
> Andrew Thompson
> http://www.PhySci.org/codes/ Web & IT Help
> http://www.PhySci.org/ Open-source software suite
> http://www.1point1C.org/ Science & Technology
> http://www.LensEscapes.com/ Images that escape the mundane



 
Reply With Quote
 
Thomas Fritsch
Guest
Posts: n/a
 
      12-02-2004
Mick wrote:
> 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?


--
"Thomas:Fritsch$ops:de".replace(':','.').replace(' $','@')

 
Reply With Quote
 
Andrew Thompson
Guest
Posts: n/a
 
      12-02-2004
> "Andrew Thompson" <(E-Mail Removed)> wrote in message
...
>> Please refrain form top-posting Mick, I find it nost confusing..
>> <http://www.physci.org/codes/javafaq.jsp#netiquette>


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

--
Andrew Thompson
http://www.PhySci.org/codes/ Web & IT Help
http://www.PhySci.org/ Open-source software suite
http://www.1point1C.org/ Science & Technology
http://www.LensEscapes.com/ Images that escape the mundane
 
Reply With Quote
 
Andrew Thompson
Guest
Posts: n/a
 
      12-02-2004
On Thu, 02 Dec 2004 19:44:08 GMT, Mick wrote:

> C:\....._jsp.java:35: expected

....

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

--
Andrew Thompson
http://www.PhySci.org/codes/ Web & IT Help
http://www.PhySci.org/ Open-source software suite
http://www.1point1C.org/ Science & Technology
http://www.LensEscapes.com/ Images that escape the mundane
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Is there a difference between +new Date() and new Date()? Nik Javascript 11 09-11-2009 07:39 PM
Finding is a given date is a month end date?? rsujatha@gmail.com Java 10 05-15-2006 06:02 AM
Finding date 1 day earlier than a given date! Edward Perl Misc 3 09-08-2004 04:51 PM
Date, date date date.... Peter Grison Java 10 05-30-2004 01:20 PM
Difference? myDate.Equals(Date.MinValue) -or- myDate = Date.MinValue Andreas Klemt ASP .Net 3 08-10-2003 03:43 AM



Advertisments