• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Comparing dates using GregorianCalendar

 
Rancher
Posts: 1090
14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 https://coderanch.com/t/594881/java/java/Comparing-dates-Java]
 
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Rancher
Posts: 1090
14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, Jeff.
 
I didn't do it. You can't prove it. Nobody saw me. The sheep are lying! This tiny ad is my witness!
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic