my dog learned polymorphism*
The moose likes Java in General and the fly likes Using java.util.Date for comparison Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Using java.util.Date for comparison" Watch "Using java.util.Date for comparison" New topic
Author

Using java.util.Date for comparison

vikram karne
Ranch Hand

Joined: Jun 05, 2007
Posts: 34
Hi Friends

I am stuck in a problem for which i need help from you.

I have written code to convert a date object into a calander object for a functionality in my application.

I am getting the output in the following format after conversion
Thu May 31 00:00:00 IST 2007
Wed Jun 13 00:00:00 IST 2007


Now inside other method i reconvert the calendar object back to Date objects.the code is as below.
Date start=filterStartDate.getTime();
Date end=filterEndDate.getTime();

Now i need to compare the 2 Date objects here and check whether the startdate is less than enddate.
the date objects are again in the same format after conversion
Thu May 31 00:00:00 IST 2007
Wed Jun 13 00:00:00 IST 2007

Can anybody let me know how to do this conversion.If possible provide me piece of code to do it.
waiting for a positive reply from you side.

Regards
Vikeng
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3482
    
  13
The Date class implements the Comparable interface so you can just dowhich will return a value less than zero if start is earlier than end.
[ June 13, 2007: Message edited by: Joanne Neal ]

Joanne
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14114
    
  16

Have you looked at the API documentation of class java.util.Date? It contains methods before() and after() that you can use.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Using java.util.Date for comparison