|
-
Jan 13th, 2005, 12:21 PM
#1
Thread Starter
Addicted Member
Subtracting Dates [Resolved]
Hi everyone,
I'm trying to write a program that regarding dates. Specifically, what I'm trying to do is this : compare two dates to see if one is less than 10 days away from the other.
EG
Code:
int days = 10;
if ( thisDate - thenextdate > days ) System.out.println ( "Less that 10 days to go" );
else System.out.println ( "No problems" );
Any help would be appreciated
Thanks
Last edited by MethadoneBoy; Jan 15th, 2005 at 04:02 PM.
Reason: Reolved Problem
"'Oh, hello Mr. Crick! What do you think of Jeffrey Archer?' Clip-clip-clip! Oh, come on! Who are you kidding? You wait til I'm mayor, you'll see how tough I am! Christ almighty...."
-
Jan 13th, 2005, 05:19 PM
#2
Frenzied Member
Re: Subtracting Dates
Well, what kind of problems is it generating?
Are you using a Calendar object to get the date or a Data object?
You could create a gregorian calendar object and then calculate the elapsed time.
Code:
import java.util.*;
public class ElapsedMillis {
public static void main(String[] args) {
GregorianCalendar date1 = new GregorianCalendar(1969, Calendar.JULY, 16, 9, 32);
GregorianCalendar gc2 = new GregorianCalendar(1995, 11, 1, 3, 2, 2);
// the above two dates are one second apart
Date d1 = date1.getTime();
Date d2 = gc2.getTime();
long l1 = d1.getTime();
long l2 = d2.getTime();
long difference = l2 - l1;
System.out.println("Elapsed milliseconds: " + difference);
}
}
I'm not for sure that this will work or that is what you want. I can't test it right now because I'm not at my laptop with the jdk.
-
Jan 13th, 2005, 05:21 PM
#3
Frenzied Member
Re: Subtracting Dates
Also, I think this checks the difference in milliseconds, so you might have to do some converting or something. But maybe someone else will help you that knows more than me.
-
Jan 15th, 2005, 04:01 PM
#4
Thread Starter
Addicted Member
Re: Subtracting Dates
No, actually what you have there is exactly what I was looking for. 
Thanks!
"'Oh, hello Mr. Crick! What do you think of Jeffrey Archer?' Clip-clip-clip! Oh, come on! Who are you kidding? You wait til I'm mayor, you'll see how tough I am! Christ almighty...."
-
Jan 15th, 2005, 04:47 PM
#5
Frenzied Member
Re: Subtracting Dates [Resolved]
Ahh cool. Glad I could help.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|