Solved

best way to compare two dates in java

Posted on 2014-03-24
5
239 Views
Last Modified: 2014-03-26
Hi,

Is there any other best method to compare two dates/compare date with today?

            Calendar cal = Calendar.getInstance();
            cal.setTime(new Date());
            cal.add(Calendar.DATE, 1);
            Date today = null;
            today = cal.getTime();
            return today.after(inputDate);
0
Comment
Question by:Rocking
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 86

Accepted Solution

by:
CEHJ earned 200 total points
ID: 39950926
0
 
LVL 28

Expert Comment

by:dpearson
ID: 39951564
Java is well known to be painful when it comes to date/time handling.

That's why an entire project has spun up to make this all simpler:
http://www.joda.org/joda-time/

Not worth using if you just need to compare 2 dates, but if you are doing a lot of date/time work it's worth it.

Doug
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 39951636
Not worth using if you just need to compare 2 dates, but if you are doing a lot of date/time work it's worth it.
Or just wait for Java 8, which contains a new date/time library, based afaik on Joda
0
 
LVL 28

Expert Comment

by:dpearson
ID: 39951998
Or just wait for Java 8, which contains a new date/time library, based afaik on Joda

Awesome!

(And Java8 came out last week I believe, so upgrade today :)
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 39956581
:)
0

Featured Post

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!

Question has a verified solution.

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

Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…

691 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