Solved

best way to compare two dates in java

Posted on 2014-03-24
5
231 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
  • 3
  • 2
5 Comments
 
LVL 86

Accepted Solution

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

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 26

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
This video teaches viewers about errors in exception handling.

743 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now