Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

best way to compare two dates in java

Posted on 2014-03-24
5
Medium Priority
?
259 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 800 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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
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…
Suggested Courses

636 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