This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds and have James Denton on-line!
See this thread for details.
Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

howto: Date arithmatic ?  RSS feed

 
Ranch Hand
Posts: 277
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've been struggling with this bit of code I was struggling with:

I'm trying to understand how to use the following methods:

I was also trying to do date arithmetic, like this

My problem is that the cal.YEAR, cal.MONTH, cal.DECEMBER and cal.DATE, 20 are hardcoded.
My attempts in using variables have thrown compile time error.
Question : How do I substitute those hardcoded String values for variables ?
TIA:-)
 
Ranch Hand
Posts: 515
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try using GregorianCalendar. This has some functionality in it so you can add days to your date.
 
Ranch Hand
Posts: 624
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can also take a look at a couple of JavaWorld articles:
  • Calculating Java dates
  • Working in Java time : Learn the basics of calculating elapsed time in Java

  • Also look at JavaAlmanac.com for some good examples ( Date Examples)
     
    achana chan
    Ranch Hand
    Posts: 277
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Thank you for the pointers and your time.
    It was very much *appreciated*.
     
    achana chan
    Ranch Hand
    Posts: 277
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Boy those articles are good, really hit the spot.
    Here's the code snippet, they work well.
    With respect to performance, should I be using GregorianCalendar or .getTime() to perform day artihmatic? I used both methods here. Can someone please comment on the relative efficiency please.

    TIA :-)
     
    Consider Paul's rocket mass heater.
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!