Tuesday, August 31, 2010

Article | Java - Comparing Two Dates



  1. import java.util.Date;

  2. public class Comparedates{

  3. public static void main(String[] args) {

  4. Date Date1 = new Date();

  5. try{

  6. Thread.sleep(1000);

  7. }catch(Exception e){

  8. }

  9. Date Date2 = new Date();

  10. System.out.println("First Date:="+Date1);

  11. System.out.println("Second Date:="+Date2);

  12. if(Date1.compareTo(Date2) > 0)

  13. System.out.println("Date1 is Greater than Date2");

  14. else if(Date1.compareTo(Date2) < 0)

  15. System.out.println("Date1 is less than Date2");

  16. else

  17. System.out.println("Date1 and Date2 are equal!!!");

  18. }

  19. }

Loading...

Comments :

0 comments to “ Java - Comparing Two Dates ”

Top Views

BloggerTipsTemplates

CHICKLETS

Enter your email address:

Delivered by FeedBurner

Followers