In this example we are going to compare two date objects in Java programming language. For comparing the date objects we can use after() method of the java.util.Date class. The after() method returns boolean value according to date objects.
In CompareDateAfter class we have defined firstDate object and then we used the Thread.Sleep(1000) method to make thread sleep for 1 second. After one second we have created another object of date class called secondDate. Now in the program we have used after() method to compare the dates.
Here is the full example code of CompareDateAfter class as follows:
FirstDate:=Wed Oct 08 18:01:14 GMT+05:30 2008
SecondDate:=Wed Oct 08 18:01:15 GMT+05:30 2008
Second Date is initialized after First Date
Posted on: October 11, 2008 If you enjoyed this post then why not add us on Google+? Add us to your Circles