Solved

best way to compare two dates in java

Posted on 2014-03-24
5
235 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 27

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 27

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

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
jdbc error in jsp application 20 86
Which non-HTML GUI front end to use with Java? 3 64
ejb entity bean example issue 2 40
servlet and mdb, jms error 1 79
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…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
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 arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Suggested Courses

738 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