Solved

Compare two date / times...

Posted on 2004-09-15
8
202 Views
Last Modified: 2010-05-18
I want to evaluate whether date/time a > date/time b.

For example, I pass in 2004-09-15-13.00.00(variable a), if that is greater than (Later than) 2004-09-15-08.00.00(variable b) then I need to flag it as "late".

The dates could be different days as well....not just times.
0
Comment
Question by:greedy1
  • 4
  • 3
8 Comments
 
LVL 86

Accepted Solution

by:
CEHJ earned 50 total points
ID: 12064020
boolean late = date1.after(date2);
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12064034
If you've got them as Strings, use SimpleDateFormat, like i showed you in your last question
0
 
LVL 37

Expert Comment

by:zzynx
ID: 12064045
if a and b are Date's:

boolean late = a.after(b);
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 37

Expert Comment

by:zzynx
ID: 12064066
>> If you've got them as Strings, use SimpleDateFormat
indeed :)
0
 
LVL 37

Assisted Solution

by:zzynx
zzynx earned 25 total points
ID: 12064103
Like

SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd-hh.mm.ss");
Date a, b;
try {
        a = sdf.parse(yourString1);
        b = sdf.parse(yourString2);
} catch (ParseException ex) {
}
0
 

Author Comment

by:greedy1
ID: 12064255
You guys have officially made me LAZY.  I briefly scanned Date javadoc, skipped over 'after()' obviously and thought I'll just go ask on EE it's easier than looking....LAZY : )

CEHJ beat you to it zzynx, but thanks for the effort , I'll increase the points and give you some too.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12064307
8-)
0
 
LVL 37

Expert Comment

by:zzynx
ID: 12064359
>> You guys have officially made me LAZY
:°D

>> CEHJ beat you to it zzynx,
Yeah, with one minute. The guy's like lightening ;°)

>> but thanks for the effort , I'll increase the points and give you some too.
much appreciated, mate. Thanks
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
null output 3 42
jsp login check 12 52
Chrome and Firefox Java 5 66
servlet and mdb, jms error 1 54
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
The viewer will learn how to implement Singleton Design Pattern in Java.

680 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question