permaculture playing cards*
The moose likes Java in General and the fly likes Comparing dates using GregorianCalendar Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Comparing dates using GregorianCalendar" Watch "Comparing dates using GregorianCalendar" New topic
Author

Comparing dates using GregorianCalendar

Chan Ag
Bartender

Joined: Sep 06, 2012
Posts: 1013
    
  15
Hi Jeff,

I've also tried to work on a similar problem in the past ( I'm also new to java and working on demo programs to get acquainted with java APIs). I passed two Date objects to a method that would call getTime() method on the two date objects and subtract the two times in milliseconds and then divide the result by 3600*24*1000 to compute the number of days. But I don't like that approach. I wanna also try the solution proposed by you. But I don't know how to create a GregorianCalendar corresponding to now. Could you please explain how to do that too.

Thanks so much.

Regards...

[MODERATOR COMMENT: Split from http://www.coderanch.com/t/594881/java/java/Comparing-dates-Java]
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Chan Go wrote:I don't know how to create a GregorianCalendar corresponding to now.


Welcome to the Ranch!

If you look at the javadocs for java.util.GregorianCalendar, I think you'll find it's obvious.
Chan Ag
Bartender

Joined: Sep 06, 2012
Posts: 1013
    
  15
Thanks, Jeff.
 
Don't get me started about those stupid light bulbs.
 
subject: Comparing dates using GregorianCalendar