Hi,
I have a date (only hours:minutes:seconds) in a text file against
which i need to compare the current time.
The date in the text file is expressed in GMT.
How do i compare and compute the difference (i am only interested in
the hours,minutes and seconds)?
The only way looks like, creating a new Date/Calendar object from the
hh:mm:ss and setting the day, month and year from a new instance of
Date/Calendar and then computing the difference.
This could run into issues when we are in the next day while GMT is
still "yesterday" during which this computation would fail.
Are there other ways to do that?
Appreciate any assistance.
Thanks,
Manglu
Andrew Thompson - 03 Oct 2007 19:28 GMT
...
>I have a date (only hours:minutes:seconds) in a text file against
>which i need to compare the current time.
If the time difference between whatever tool is writing
that file, and your app. is unknown, ..
>The date in the text file is expressed in GMT.
>
>How do i compare and compute the difference (i am only interested in
>the hours,minutes and seconds)?
..this would seem to be an incomputable problem.
OTOH If the time difference can be obtained. ..
>The only way looks like, creating a new Date/Calendar object from the
>hh:mm:ss and setting the day, month and year from a new instance of
>Date/Calendar and then computing the difference.
>
>This could run into issues when we are in the next day while GMT is
>still "yesterday" during which this computation would fail.
.. Do as you were desribing, but subtract (the known time
difference from current time).

Signature
Andrew Thompson
http://www.athompson.info/andrew/
edgar - 03 Oct 2007 19:31 GMT
On Oct 3, 10:43 am, Mangalaganesh Balasubramanian <man...@gmail.com>
wrote:
> Hi,
>
[quoted text clipped - 19 lines]
> Thanks,
> Manglu
I assume you'll be comparing the time in your file to the current
time, which is the system time. So I don't think you'll have a need to
create a Date/Calendar object. You might want to look into
java.lang.System
Lew - 03 Oct 2007 22:01 GMT
> On Oct 3, 10:43 am, Mangalaganesh Balasubramanian <man...@gmail.com>
> wrote:
[quoted text clipped - 11 lines]
>> hh:mm:ss and setting the day, month and year from a new instance of
>> Date/Calendar and then computing the difference.
Yes, that's a convenient and easy way to do what you're asking.
>> This could run into issues when we are in the next day while GMT is
>> still "yesterday" during which this computation would fail.
That doesn't make sense. If you compare GMT (really, UTC) times, then you are
getting a valid comparison. You've eliminated time zone issues. What are you
referring to?
> I assume you'll be comparing the time in your file to the current
> time, which is the system time. So I don't think you'll have a need to
> create a Date/Calendar object. You might want to look into
> java.lang.System
Why the aversion to creating a Calendar or Date object?
How does System help? What's wrong with:
Calendar calNow = Calendar.getInstance();
Calendar calStored = Calendar.getInstance();
calStored.set( yearFromFile(), monthFromFile(), dayFromFile(),
hourFromFile(), minFromFile(), secFromFile() );
// DateFormat would help here
long diffInMs = calNow.getTimeInMillis() - calStored.getTimeInMillis();
etc.?

Signature
Lew
Roedy Green - 04 Oct 2007 03:07 GMT
On Wed, 03 Oct 2007 17:43:59 -0000, Mangalaganesh Balasubramanian
<manglu@gmail.com> wrote, quoted or indirectly quoted someone who said
>Hi,
>
[quoted text clipped - 5 lines]
>How do i compare and compute the difference (i am only interested in
>the hours,minutes and seconds)?
see http://mindprod.com/jgloss/time.html
http://mindprod.com/jgloss/calendar.html

Signature
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
Chris - 04 Oct 2007 03:57 GMT
> Hi,
>
[quoted text clipped - 14 lines]
>
> Are there other ways to do that?
I'm not sure the best approach for your particular app, but if you can
avoid using Dates and Calendars and the like, you're better off (usually).
Think about converting to millis (System.currentTimeMillis) or doing
string or int comparisons. Calendars only make sense when you have to do
complicated date manipulations which can't easily be done with primitives.