• 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
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Devaka Cooray
  • Ron McLeod
  • paul wheaton
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Frits Walraven
  • Scott Selikoff

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.
 
Hey, I'm supposed to be the guide! Wait up! No fair! You have the tiny ad!
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic