> there is no method to get the difference between dates.
True, but he doesn't need to by the sound of it.
You also said he needed to do the calculations to solve his problem...
------------
import java.util.*;
public class DateFunc {
public static void main(String args[])
{
Calendar timenow = Calendar.getInstance();
Calendar timesub24 = Calendar.getInstance();
Date nowdate = new Date();
timenow.setTime(nowdate);
timesub24.setTime(nowdate);
timesub24.add(Calendar.HOUR, -24);
System.out.println("Time now: " + timenow.getTime());
System.out.println("Time 24hrs ago: " + timesub24.getTime());
// Compare your stored date against "timesub24" using "before" or "after",
job done.
}
}
---------
-ldr
----- Original Message -----
From: "Bhushan_Bhangale" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Tuesday, July 23, 2002 11:14 AM
Subject: Re: Calendar object
I guess you haven't got my statement fully. I said there is no method to get
the difference between dates. One need to use indirect method like which you
just told.
-----Original Message-----
From: Liam Redmond [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, July 23, 2002 3:01 PM
To: [EMAIL PROTECTED]
Subject: Re: Calendar object
> As such there is no method in all the date related class
What are these then?
abstract public boolean before(Object cal);
abstract public boolean after(Object cal);
These are helpful too...
abstract public void add(int fld, int amount)
abstract public void roll(int fld, boolean up)
These methods are specifically for comparing dates and finding differences
between dates. To answer your question take the date now, subtract a day
from it and use the before or after methods against your static calendar
var. Don't waste your time doing all the maths, Sun have already done it.
-ldr
----- Original Message -----
From: "Bhushan_Bhangale" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Tuesday, July 23, 2002 4:18 AM
Subject: Re: Calendar object
You need to do all the calculations. As such there is no method in all the
date related class which gives the difference between two dates.
-----Original Message-----
From: Falls, Travis D (CASD, IT) [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, July 23, 2002 1:20 AM
To: [EMAIL PROTECTED]
Subject: Calendar object
Hello,
I want to figure out if the current date/time is 24 hours or longer from a
static Calendar Var that I have stored. Is there a way to subtract the two
objects? Or do I have to do all the calculations.
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html