In this example we are going to compare two date objects using java.util.Date class. For comparing dates, we will be using compareTo() method. The compareTo() method returns integer value after comparing the dates.
In CompareDate example class we have defined firstDate object and then we used the Thread.Sleep(1000) method to make thread to sleep for 1 second and then it creates new object secondDate after. So that second date is created after one second of creation of firstDate. Now in our example program we can compare these two dates using compareTo() method.
Here is the full example code of CompareDate class as follows:
FirstDate:=Wed Oct 08 17:22:05 GMT+05:30 2008
SecondDate:=Wed Oct 08 17:22:06 GMT+05:30 2008
Second Date is initialized after First Date
Rs. 20,000 US$ 300
Today: Rs. 10,000 US$150
Course Duration: 30 hrs
Posted on: October 11, 2008 If you enjoyed this post then why not add us on Google+? Add us to your Circles