• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 268
  • Last Modified:

best way to compare two dates in java

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
Rocking
Asked:
Rocking
  • 3
  • 2
1 Solution
 
CEHJCommented:
0
 
dpearsonCommented:
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
 
CEHJCommented:
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
 
dpearsonCommented:
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
 
CEHJCommented:
:)
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now